Grails many-to-many belongsTo
Asked Answered
S

1

10

I want a many-to-many relationship. Then i have to specify a belongsTo at one side like:

static belongsTo = Answer

But i already have specified a belongsTo as a Map: here the 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

But I can't specify an owner in the Filter because I already have the user owner for the Filter...

How do I do this?

edit: sorry figured out the solution by myself:

class Filter {

    String name
    User user
    static hasMany = [answers:Answer]
    static belongsTo = [User, Answer]
}
Selfsupport answered 10/2, 2012 at 11:58 Comment(1)
You should post your solution as an answer and accept it so people can know that this question has been answered.Sivan
V
4

Posting the @user1200271 answer, just to remove from the unaswered list.

class Filter {
    String name
    User user
    static hasMany = [answers:Answer]
    static belongsTo = [User, Answer]
}
Vano answered 12/3, 2013 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.