grails - 属于多个域

标签 grails grails-orm grails-plugin grails-domain-class grails-2.0

我有 4 个类(class)、事件、问题、请求,另一个是附件。

每个域看起来都像......

    Class Incidents
    {
    // other fields
       static hasOne = [attachment: Attachment]

       static constraints = [attachment nullable:true]
    }

    Class Problems
    {
    // other fields
       static hasOne = [attachment: Attachment]

       static constraints = [attachment nullable:true]
    }

    Class Requests
    {
    // other fields
       static hasOne = [attachment: Attachment]

       static constraints = [attachment nullable:true]
    }

    Class Attachment
    {
    // other fields
       static belongsTo= [
                   incident: Incidents, 
                   problem: Problems,
                   requests: Requests
]

   static constraints = {
        incident nullable: true
        problem nullable: true
        requests nullable: true
}

当我保存事件对象时,它会抛出异常,例如列“problem_id”不能为空。 该怎么办?

最佳答案

尝试删除类事件、问题、请求上的 hasOne 并将其替换为

   Attachment attachment
   static constraints = {attachment: unique: true, nullable:true}       
   static mapping = {
    attachment  cascade: "delete"
    }

关于grails - 属于多个域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11077871/

相关文章:

grails - Grails filterPane插件适合页面布局

grails - 如何嵌套插件URL?

grails - 如何将 grails 3 插件发布到我的本地 nexus 存储库?

grails - 带有grails的验证程序:无法创建用户

grails - 如何防止 Grails 域被更新或删除?

hibernate - GORM : hql query produces exception: could not resolve property

Grails 2.0.0.RC3 : Could not reload changes to controller, java.lang.NoSuchFieldException: __timeStamp__239_neverHappen1323622798918

Hibernate 条件 - 获取单个对象

每次提交命令对象时,Grails 2.3.7 乐观锁定版本都会更新

grails - HTML5拖放多文件上传grails插件