[英]Doctrine One-To-One bidirectional relationship CASCADE direction
我有两个使用yaml注释定义的学说实体(User和DatiFiscali),如下所示。
我想要实现的是删除用户时还要在级联上删除DatiFiscali ,
但是使用下面的配置我只能获得相反的行为:当删除DatiFiscali时 , 用户也将在级联上被删除。
我可以通过手动添加以下外键轻松获得所需的结果:
CONSTRAINT `datifiscali_ibfk_1` FOREIGN KEY (`id`) REFERENCES `User` (`datifiscali_id`) ON DELETE CASCADE
但是,当使用“docrine orm:schema-tool:update”doctrine正确地更新模式时,将尝试DROP上面的外键。
在没有任何方式可以实现上述目的:
实体A:
Test\User:
type: entity
table: User
id:
id:
type: integer
generator:
strategy: AUTO
fields:
username:
type: text
nullable: true
email:
type: text
nullable: true
oneToOne:
datiFiscali:
targetEntity: DatiFiscali
inversedBy: user
joinColumns:
datifiscali_id:
referencedColumnName: id
onDelete: CASCADE
实体B:
Test\DatiFiscali:
type: entity
table: DatiFiscali
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
type: text
nullable: true
surname:
type: text
nullable: true
business_name:
type: text
nullable: true
oneToOne:
user:
targetEntity: User
mappedBy: datiFiscali
谢谢您的帮助!
尝试将级联选项放在正确的位置:
oneToOne:
datiFiscali:
targetEntity: DatiFiscali
inversedBy: user
joinColumns:
datifiscali_id:
referencedColumnName: id
cascade: ["remove"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.