我想要多对多的关系。然后我必须在一侧指定一个belongsTo,例如:
static belongsTo = Answer
但是我已经指定了一个名为belongsTo的 map :这里的代码
class Answer {
String text
static hasMany = [users:User, filters:Filter]
static belongsTo = [question:Question]
}
class User {
String name
static hasMany = [answers:Answer]
static belongsTo = Answer
}
class Filter {
String name
static hasMany = [answers:Answer]
static belongsTo = [user:User]
//static belongsTo = Answer
但是我无法在过滤器中指定所有者,因为我已经拥有过滤器的用户所有者...
我该怎么做呢?
编辑:很抱歉自己找出了解决方案:
class Filter {
String name
User user
static hasMany = [answers:Answer]
static belongsTo = [User, Answer]
}
最佳答案
发布@ user1200271答案,只是从未答复的列表中删除。
class Filter {
String name
User user
static hasMany = [answers:Answer]
static belongsTo = [User, Answer]
}
关于多对多的Grails属于,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9227393/