我有這個rekation以下實體:doctrine2違反約束
/**
* 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;
當我嘗試刪除的對象喜歡這裏:
$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;
我可以做我想做的事情,我得到以下錯誤:
An exception occurred while executing 'DELETE FROM book WHERE pkId = ?' with params {"1":3928}: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (
p1
.book
, CONSTRAINTFK_F51A442F78734022
FOREIGN KEY (fkstatistic
) REFERENCESbookstatistic
(pkId
))
有一個想法我做錯了什麼? 我嘗試了很多方法,但沒有任何幫助。
你的關聯實體是什麼樣的?你確定你需要'orphanRemoval'和所有級聯選項嗎? – Ocramius 2013-02-12 11:16:03
的主要問題是,我必須刪除統計對象,當我刪除書,我想我可以做它whith級聯刪除或orphanremoval。我如何向你展示關聯的實體? – 2013-02-12 11:33:05