2

インシデント、問題、リクエストの 4 つのクラスがあり、もう 1 つは添付ファイルです。

すべてのドメインは次のようになります........

    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
}

インシデントのオブジェクトを保存しているときに、Column 'problem_id' cannot be null のような例外がスローされます。何をすべきか?

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 に答える