apache / apache/grails-core

Nested objects have to be set as "embedded" even when they are all in src/main/groovy.

Open
#14,362 0 comments 0 reactions 1 assignee Claimed by @puneetbehl View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Nested objects have to be set as "embedded" to be persisted even when they are all in src/main/groovy. I believe non entity classes should always be saved as embedded objects. Above all, non entity objects should never have to have `static embedded` declarations.

The following test only pass when the commented lines get uncommented. I believe it would be more appropriate if it passed even without those commented lines.

```package org.grails.datastore.gorm.mongo

import grails.gorm.tests.GormDatastoreSpec
import grails.persistence.Entity

class EmbeddedWithinEmbeddedSimpleObjectSpec extends GormDatastoreSpec {

void "Test embedded nested non-domain object"() {
when:"An entity with a simple nested non-domain embedded object is persisted"
def constellation = new Constellation(displayName: "foo", solarSystem: new SolarSystem(planet: new Planet(name: "earth")))
constellation.save(flush:true)
session.clear()
constellation = Constellation.get(constellation.id)
then:"The embedded association is persisted correctly"
constellation.solarSystem?.planet?.name == 'earth'
}

@Override
List getDomainClasses() {
[Constellation]
}
}

@Entity
class Constellation {

String id
String displayName

SolarSystem solarSystem

static embedded = [ 'solarSystem' ]
}

//@Entity
class SolarSystem {
Planet planet

// static embedded = [ 'planet' ]
}

//@Entity
class Planet {
String name
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.