2012-11-23 74 views
5

Mam następujące dwie klasy domen, Użytkownik i posty Mam między nimi dwie relacje, Użytkownik ma jeden-do-wielu z Postami z oparciem wstecznym . Użytkownik ma wiele do wielu relacji z postów, że następuje: relacji Mam przedstawiają się następująco:Grails Wiele-do-wielu i jeden-do-wielu zderzyć

User { 
hasMany = [posts : Post, followingPosts: Post] 
belongsTo = [Post] //For the many-to-many, this is the owner i'd like to have. 

} 

Post { 
    hasMany = [followers: User] 
    belongsTo = [owner: User] //For the 1-to-Many, this is my back-reference 
} 

Teraz dostaję starcia z Grails, próbowałem go rozwiązać poprzez mapowanie ale bez powodzenia, jest to błąd, który otrzymuję:

Domain classes [Post] and [User] cannot own each other in a many-to-many relationship. Both contain belongsTo definitions that reference each other. (Use --stacktrace to see the full trace) 

Ktoś wie, jak rozwiązać ten problem?

Odpowiedz

1

myślę, że można to zrobić za pomocą mappedBy, jak:

class User{ 

    static hasMany = [posts : Post, followingPosts: Post] 
    static mappedBy = [posts : "user"] 
} 


class Post{ 

    User user 
    static hasMany = [followers: User] 
    static belongsTo = User 
} 

Spójrz na this uzyskać więcej informacji na temat mappedBy.