Grails 属于多个域

Grails 属于多个域,grails,gorm,grails-plugin,grails-domain-class,grails-2.0,Grails,Gorm,Grails Plugin,Grails Domain Class,Grails 2.0,我有4个类,事件,问题,请求和另一个是附件 每个域看起来都像 Class Incidents { // other fields static hasOne = [attachment: Attachment] static constraints = [attachment nullable:true] } Class Problems { // other fields static has

我有4个类,事件,问题,请求和另一个是附件

每个域看起来都像

    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'不能为null。
怎么办?

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

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

如果我删除了该关系,那么它是否允许级联删除?对于级联删除,请尝试添加级联映射。我已经更新了答案。