Grails 多对多关系

发布于 2024-09-14 09:20:47 字数 867 浏览 6 评论 0原文

我试图在 Grails 1.3.4 上建立多对多关系,但遇到了这个异常:

Caused by: org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner defined between domain 
classes [class gblog.Post] and [class gblog.Comentario] in a many-to-many relationship. 
Example: static belongsTo = gblog.Comentario

Comentario 的代码是:

package gblog

class Comentario {

    static constraints = {
    }

    String conteudo
    Date data

    static belongsTo = [post:Post, autor:Usuario]
    static hasMany = [posts:Post]
}

Post 的代码是:

package gblog

class Post {

    static constraints = {
    }

    String titulo
    String conteudo
    String palavrasChave
    Date data

    static belongsTo = [categoria:Categoria, autor:Usuario]
    static hasMany = [comentarios:Comentario]
}

谢谢大家!

I'm trying to do a many-to-many relationship on Grails 1.3.4 and I'm getting this exception:

Caused by: org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner defined between domain 
classes [class gblog.Post] and [class gblog.Comentario] in a many-to-many relationship. 
Example: static belongsTo = gblog.Comentario

The code for Comentario is:

package gblog

class Comentario {

    static constraints = {
    }

    String conteudo
    Date data

    static belongsTo = [post:Post, autor:Usuario]
    static hasMany = [posts:Post]
}

The code for Post is:

package gblog

class Post {

    static constraints = {
    }

    String titulo
    String conteudo
    String palavrasChave
    Date data

    static belongsTo = [categoria:Categoria, autor:Usuario]
    static hasMany = [comentarios:Comentario]
}

Thanks everybody!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2024-09-21 09:20:47

我认为 Grails 在这里变得很困惑:

static belongsTo = [post:Post, autor: Usuario]
static hasMany = [posts:Post]

您可能想要绘制所有类如何交互的图表,因为我认为这有点不对劲。

I think Grails is getting confused here:

static belongsTo = [post:Post, autor: Usuario]
static hasMany = [posts:Post]

You might want to diagram how all of the classes are interacting, because I'm thinking that this is a little off.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文