belongsTo multiple Domain

醉酒当歌 提交于 2019-12-06 13:40:32

问题


I have 4 classes, incidents,problems, requests and another is Attachment.

Every domain look like.........

    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
}

when I am saving object of incident, it throws exception like Column 'problem_id' cannot be null. what to do?


回答1:


Try to remove the hasOne on Class Incidents, Problems, Requests and replace it with

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


来源:https://stackoverflow.com/questions/11077871/belongsto-multiple-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!