2

我有 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'不能为空。该怎么办?

4

1 回答 1

5

尝试删除 Class Incidents, Problems, Requests 上的 hasOne 并将其替换为

   Attachment attachment
   static constraints = {attachment: unique: true, nullable:true}       
   static mapping = {
    attachment  cascade: "delete"
    }
于 2012-06-18T08:43:21.317 回答