【发布时间】:2011-05-25 16:02:33
【问题描述】:
我有两个实体
TB\Entity\UserProfile
/**
* @OneToMany(targetEntity="TB\Entity\ShopVideo", mappedBy="shop",
* cascade={"persist", "remove"}
* )
*/
private $video;
和 TB\Entity\ShopVideo
/**
* @var UserProfile
*
* @ManyToOne(targetEntity="TB\Entity\UserProfile")
* @JoinColumns({
* @JoinColumn(name="shop", referencedColumnName="id")
* })
*/
private $shop;
如果我这样创建 UserProfile 实例和 ShopVideo 实例
$profile = new TB\Entity\UserProfile();
$model = new TB\Entity\ShopVideo();
$profile->getShopVideo()->add($model);
$this->_em->persist($profile);
$this->_em->flush();
我希望用“UserProfile”的 id 填充“商店”列(以及其他有效的模型)...但是我收到错误(由于外键限制)
PDOException:SQLSTATE[23000]:违反完整性约束:1048 列“shop”不能为空
/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 设置商店列?任何帮助将不胜感激!
【问题讨论】:
标签: doctrine-orm