In grails, when specifying a unidirectional one-to-one relationship, I can do either
class MyDomainClass {
AnotherDomainClass another
}
or
class MyDomainClass {
static hasOne = [another:AnotherDomainClass]
}
I know the semantics are different, but either way will establish this relationship.
When creating a hasMany relationship, I can do:
class MyDomainClass {
static hasMany = [others:AnotherDomainClass]
}
But I can't seem to do:
class MyDomainClass {
List<AnotherDomainClass> others
}
Edit: Clarification. I would like to still have the hasMany relationship, I'm just wondering if it's possible to do so just by declaring List<AnotherDomainClass> others
without the hasMany
variable. I was hoping that just declaring List<AnotherDomainClass>
would create a join table automatically.
Yes, you can do. Just declare both.
class MyDomainClass {
List<AnotherDomainClass> others
static hasMany = [others:AnotherDomainClass]
}
When you not declare the field, Grails automatically create a Set
for you.