我有兩個相關對象:級聯工作,其混亂
用戶
/**
* @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.
在我看來移除應該工作打完電話後註釋但沒有成功。我需要有人來解釋我做錯了什麼,我該怎麼做。