2012-11-23 5 views
5

다음 두 도메인 클래스가 있습니다 사용자와 게시물 그리고 두 사람 사이에 관계가 있습니다 사용자가 1 : 다수의 게시물과 역 참조 . 다음과 같습니다 내가있어 관계 : 사용자가 대다 그 다음 것을 게시물과 관계를 가지고Grails 다 대다와 일대 다 충돌

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 
} 

가 지금은 Grails를 가진 충돌을지고있어, 내가지도를 통해 해결을 시도하지만, 성공하지 못하면 다음과 같은 오류가 발생합니다.

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) 

누구든지 해결 방법을 알고 계십니까?

답변

1

나는 당신처럼, mappedBy 사용하여 할 수 있다고 생각 :

class User{ 

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


class Post{ 

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

mappedBy에 대한 자세한 정보를 원하시면 this를 살펴 보자.