Grails GORM多对多关系

Grails GORM多对多关系,grails,groovy,orm,gorm,Grails,Groovy,Orm,Gorm,当其父用户被删除时,我想删除所有的推文,当其父推文被删除时,我还想删除协作者。其中合作者如果属于用户 目前,Tweet视图没有连接协作者。我在想,如果我做对了以下几点: Tweet.groovy User owner static hasMany = [ collaborators : User ] static belongsTo = User static hasMany = [ tweet : Tweet ] static hasMany = [ collaborators : Us

当其父
用户
被删除时,我想删除所有的
推文
,当其父
推文
被删除时,我还想删除协作者。其中
合作者
如果属于
用户

目前,Tweet视图没有连接协作者。我在想,如果我做对了以下几点:

Tweet.groovy

User owner
static hasMany = [ collaborators : User ]
static belongsTo = User
static hasMany = [ tweet : Tweet ] 
static hasMany = [ collaborators : User ]
static belongsTo = User
User createdBy
static mappedBy = [collaborators : 'tweet']
static hasMany = [ tweet : Tweet ]
static mappedBy = [tweet : 'collaborators']
User.groovy

User owner
static hasMany = [ collaborators : User ]
static belongsTo = User
static hasMany = [ tweet : Tweet ] 
static hasMany = [ collaborators : User ]
static belongsTo = User
User createdBy
static mappedBy = [collaborators : 'tweet']
static hasMany = [ tweet : Tweet ]
static mappedBy = [tweet : 'collaborators']

在我看来,你缺少一种关系,即推特是由特定用户拥有的。现在你只会得到一个多对多的关系,我猜你不想在删除一个用户时删除所有用户合作的推文

Tweet.groovy

User owner
static hasMany = [ collaborators : User ]
static belongsTo = User
static hasMany = [ tweet : Tweet ] 
static hasMany = [ collaborators : User ]
static belongsTo = User
User createdBy
static mappedBy = [collaborators : 'tweet']
static hasMany = [ tweet : Tweet ]
static mappedBy = [tweet : 'collaborators']
User.groovy

User owner
static hasMany = [ collaborators : User ]
static belongsTo = User
static hasMany = [ tweet : Tweet ] 
static hasMany = [ collaborators : User ]
static belongsTo = User
User createdBy
static mappedBy = [collaborators : 'tweet']
static hasMany = [ tweet : Tweet ]
static mappedBy = [tweet : 'collaborators']

上面的mappedBy是必需的,因为类之间有两种关系,Grails需要知道多对多使用哪种关系。

错误:在多对多关系中的域类[class com.brewee.User]和[class com.brewee.Tweet]之间没有定义所有者。示例:static belongsTo=com.brewee.tweet接受的答案是正确的语法,但解决方案是相同的。选择公认的答案。我将编辑我的回复,使其正确无误,以免混淆任何人。正在尝试