2012-11-23 31 views
5

Ho le seguenti due classi di dominio, E ho due relazioni tra loro, L'utente ha 1-a-molti con Post con riferimento posteriore . utente ha molti-a-molti rapporti con i messaggi che egli segue: I rapporti che ho ottenuto sono le seguenti:Grail Molti-a-molti e uno-a-molti scontro

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 
} 

Ora sto ottenendo uno scontro con Grails, ho provato a risolverlo attraverso la mappatura, ma senza successo, questo è l'errore che ottengo:

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) 

Qualcuno sa come risolvere questo?

risposta

1

penso che si può farlo utilizzando mappedBy, come:

class User{ 

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


class Post{ 

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

Date un'occhiata a this per maggiori informazioni sul mappedBy.

Problemi correlati