php - doctrine2 constraint violation -
i have next entity rekation:
/** * acme\demobundle\entity\book * * @orm\table(name="book") * @orm\entity(repositoryclass="acme\demobundle\repository\bookrepository") * @orm\haslifecyclecallbacks * @uniqueentity(fields="publickey", groups={"publickey"}) */ class p1guestlistentry { /** * @var p1guestlistentrystatistic * * @orm\onetoone(targetentity="p1guestlistentrystatistic", orphanremoval=true, cascade={"all"}, fetch="eager") * @orm\joincolumns({ * @orm\joincolumn(name="fkstatistic", referencedcolumnname="pkid", nullable=false) * }) */ private $fkstatistic; when seek remove object here:
$this->getentitymanager()->getconnection()->begintransaction(); try{ $book = $this->getentitymanager()->getrepository('achmedemobundle:book')->find(3928); $this->getentitymanager()->remove($book); $this->getentitymanager()->flush(); $this->getentitymanager()->getconnection()->commit(); }catch(exception $e){ $this->getentitymanager()->getconnection()->rollback(); echo $e->getmessage(); } exit; i can whatever want, next error:
an exception occurred while executing 'delete book pkid = ?' params {"1":3928}: sqlstate[23000]: integrity constraint violation: 1451 cannot delete or update parent row: foreign key constraint fails (p1.book, constraint fk_f51a442f78734022 foreign key (fkstatistic) references bookstatistic (pkid))
has anbybody thought i'm doing wrong? tried lot of methods nil helps.
in case runs similar issue, here solution:
/** * @var statistic * * @orm\onetoone(targetentity="statistic", cascade="all") * @orm\joincolumns({ * @orm\joincolumn(name="fkstatistic", referencedcolumnname="pkid", ondelete="set null") * }) */ the ondelete alternative remove relation first , doctrine cascade operation.
php symfony2 doctrine2
No comments:
Post a Comment