Grails多对多属于

时间:2012-02-10 11:58:29

标签: grails many-to-many gorm belongs-to

我想要多对多的关系。然后我必须在一侧指定belongsTo,如:

static belongsTo = Answer

但我已经将belongsTo指定为Map:这里是Code

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]
}

1 个答案:

答案 0 :(得分:4)

发布@ user1200271答案,只是从未答复的列表中删除。

class Filter {
    String name
    User user
    static hasMany = [answers:Answer]
    static belongsTo = [User, Answer]
}