문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top