我有两个相关对象:级联工作,其混乱
用户
/**
* @ORM\OneToOne(targetEntity="File", mappedBy="userProfileImage")
*/
protected $profileImage;
文件在我的数据库
/**
* @ORM\OneToOne(targetEntity="User", inversedBy="profileImage")
* @ORM\JoinColumn(name="userProfileImage", referencedColumnName="id", onDelete="SET NULL")
*/
protected $userProfileImage;
和两个相关记录。我想删除旧的File对象并将其替换为新的File。问题是我无法删除文件的对象,因为我有以下错误:
$this->getDoctrine()-getManager()->remove($user->getProfileImage());
$this->getDoctrine()-getManager()->flush();
我尝试添加cascade={"all"}
和cascade={"persist", "remove"}
到$profileImage
:
A new entity was found through the relationship 'MyBundle\Entity\User#profileImage' that was not configured to cascade persist operations for entity: MyBundle\Entity\[email protected] To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'MyBundle\Entity\File#__toString()' to get a clue.
在我看来移除应该工作打完电话后注释但没有成功。我需要有人来解释我做错了什么,我该怎么做。