2012-11-23 18 views
5

Ben şu iki etki alanı sınıfları, Kullanıcı ve Mesajlar Ve aralarında iki ilişkiler, Kullanıcı 1-çok geri referansla Mesajlar sahiptir var . aşağıdaki gibidir bende ilişkileri: Kullanıcı pek-çok o izler mesajlar ile ilişkileri vardırGrails To-Many-Birçok ve One-çok çatışma

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 
} 

Şimdi Grails ile bir çatışma alıyorum, ben haritalama aracılığıyla çözme denedim ama hiçbir başarı ile, bu benim aldığım hata:

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) 

Bunu nasıl çözeceğini bilen var mı?

cevap

1

ben sizin gibi, mappedBy kullanarak bunu yapabilirsiniz düşünüyorum:

class User{ 

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


class Post{ 

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

mappedBy hakkında daha fazla bilgi için this bir göz atın.