Grails多对多的关系

时间:2010-08-17 15:58:32

标签: grails relationship

我正在尝试在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的代码是:

包gblog

class Post {

    static constraints = {
    }

    String titulo
    String conteudo
    String palavrasChave
    Date data

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

谢谢大家!

1 个答案:

答案 0 :(得分:1)

我认为Grails在这里感到困惑:

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

您可能想要绘制所有类的交互方式,因为我认为这有点不对。