Grails多对多和一对多的冲突

use*_*198 5 java grails entity-relationship grails-orm relationship

我有以下两个域类,用户和帖子我和他们之间有两个关系,用户有一对多的帖子有后引用.用户与他所关注的帖子有多对多的关系:我得到的关系如下:

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
}
Run Code Online (Sandbox Code Playgroud)

现在我和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)
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这个问题?

Tia*_*ias 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
}
Run Code Online (Sandbox Code Playgroud)

查看此内容以获取有关mappedBy的更多信息。