grails,relations和cascade delete

时间:2014-01-11 15:02:09

标签: database grails relation cascading-deletes

我有以下域类:

class Patient {
    ...
}

class Receipt{
@NotNull
static belongsTo = [patient:Patient]
...
}

如果我尝试删除Patient实例(创建Receipt个实例后),我有一个MySQLIntegrityConstraintViolationException。请注意,患者可以拥有零对多的收据。

1 个答案:

答案 0 :(得分:1)

要完成父子关系,请在父域类中创建多个部分:

class Patient {
static hasMany = [receipts: Receipt]
    ...
}

class Receipt{
@NotNull
static belongsTo = [patient:Patient]
...
}