0

我想删除与另一个实体的一对一关系相关的实体。但我总是失败。这是我尝试过的代码:

$adminid=$centrex->getDefadmin()->getId();
$defadmin = $em->getRepository('TelnOperatorBundle:Defadmin')->find($adminid);
$em->remove($defadmin);
    $em->flush();

有人可以帮助我吗?问题如下:

An exception occurred while executing 'DELETE FROM DefAdmin WHERE id = ?' with params {"1":"5"}:

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`symfony`.`centrex`, CONSTRAINT `FK_63C80A4692343E35` FOREIGN KEY (`defadmin_id`) REFERENCES `defadmin` (`id`)) 
4

2 回答 2

0

请查看教义文档。关于与协会合作:

http://docs.doctrine-project.org/en/2.0.x/reference/working-with-associations.html

特别是删除时的级联您会感兴趣,请参阅链接文档上的第 8.6 点。

于 2013-04-19T11:21:35.093 回答
0

onDelete=Cascade将此添加到您的实体上

于 2013-04-25T05:36:19.370 回答