Grails 映射问题 - 多对多
我有以下结构
class User{
List<Post> posts = new ArrayList<Post>();
static hasMany = [posts: Post]
}
class Post{
User user
List<User> subscribers = new ArrayList<User>();
static belongsTo = [user: User]
static hasMany = [subscribers: User]
}
,它显示
原因: org.codehaus.groovy.grails.exceptions.GrailsDomainException:没有所有者 定义在域类 [class User] 和 [class Post] 之间 多对多关系。示例:静态belongsTo = Post
- 一个用户可以有多个帖子
- 一个帖子属于一个用户
- 一个帖子可以有多个订阅者
版本 Grails 1.3.7
I have following structure
class User{
List<Post> posts = new ArrayList<Post>();
static hasMany = [posts: Post]
}
class Post{
User user
List<User> subscribers = new ArrayList<User>();
static belongsTo = [user: User]
static hasMany = [subscribers: User]
}
and it shows
Caused by:
org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner
defined between domain classes [class User] and [class Post] in a
many-to-many relationship. Example: static belongsTo = Post
- A user can have multiple post
- A Post belongs to a User
- A Post can have multiple subscribers
Version Grails 1.3.7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,这意味着在相同的两个类之间创建多对多关系和一对多关系。
执行此操作的方法如下:
用户类别:
帖子类别:
我在 此讨论
I had the same problem, meaning creating a many to many relationship AND a 1 to many relationship between the same two classes.
The way to do that is as following:
User class:
Post class:
I've found that answer in this discussion