1
我有兩個實體奇怪的級聯行爲Doctrine2
TB\Entity\UserProfile
/**
* @OneToMany(targetEntity="TB\Entity\ShopVideo", mappedBy="shop",
* cascade={"persist", "remove"}
*)
*/
private $video;
和 TB \實體\ ShopVideo
/**
* @var UserProfile
*
* @ManyToOne(targetEntity="TB\Entity\UserProfile")
* @JoinColumns({
* @JoinColumn(name="shop", referencedColumnName="id")
* })
*/
private $shop;
如果我創建一個用戶配置實例和ShopVideo實例作爲如此
$profile = new TB\Entity\UserProfile();
$model = new TB\Entity\ShopVideo();
$profile->getShopVideo()->add($model);
$this->_em->persist($profile);
$this->_em->flush();
我期望'shop'欄填入'UserProfile'的id(和其他模型這工作)......但是我得到的錯誤(由於外鍵約束)
PDOException:SQLSTATE [23000]:完整性約束違規:1048列「店」不能爲空
/Users/ABCD/work/TB/TB/library/Doctrine/DBAL/Statement.php:131
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/Persisters/BasicEntityPersister.php:226
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/UnitOfWork.php:698
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/UnitOfWork.php:280
/Users/ABCD/work/TB/TB/library/Doctrine/ORM/EntityManager.php:328
我只是不明白爲什麼ShopVideo不會級聯操作並將店鋪列設置爲USerProfile的ID?任何幫助,將不勝感激!