简体   繁体   English

grails,关系和级联删除

[英]grails, relations and cascade delete

I have the following domain classes: 我有以下域类:

class Patient {
    ...
}

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

If I try to delete a Patient instance (after creation of Receipt instances), I have a MySQLIntegrityConstraintViolationException . 如果我尝试删除Patient实例(在创建Receipt实例之后),则我有一个MySQLIntegrityConstraintViolationException Notice that a patient can have zero-to-many receipts. 请注意,患者可以有零对多收据。

To complete the parent child relationship, create a has many section in the parent domain class: 要完成父子关系,请在父域类中创建一个具有许多部分的部分:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM