2012-11-23 20 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 पर एक नजर डालें।

संबंधित मुद्दे