开发者

Overcoming "No owner defined between domain classes" in Grails many-to-many relationship

开发者 https://www.devze.com 2023-03-03 22:36 出处:网络
I was following the \"Grails in Action\" book开发者_Python百科 in order to create the following scenario.

I was following the "Grails in Action" book开发者_Python百科 in order to create the following scenario.

A map belongs to one or many mapsets. A mapset can contain one or many maps. Both belong to a user.

So, what I did was:

Map.groovy:

static hasMany = [ sets : Mapset ]
static belongsTo = [ user : User, set : Mapset ]

Mapset.groovy:

static hasMany = [ maps : Map ]
static belongsTo = [ user : User ]

User.groovy:

static hasMany = [ maps : Map, sets: Mapset ]

Still, I receive this error when running the app:

Caused by: org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner defined between domain classes [class at.package.Mapset] and [class at.package.Map] in a many-to-many relationship. Example: static belongsTo = at.package.Map

It doesn't change anything if I write the fully qualified class name for Map.


Whoops, this is weird. The following the trick:

In Map.groovy:

static belongsTo = [ User, Mapset ]

I'd probably keep this as an answer instead of deleting the question because there's no reference for this error message on SO yet

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号