[英]Doctrine2 ManyToMany Self referencing
我遇到了許多自我引用關系的問題。 我收到錯誤:
在鏈配置的命名空間中找不到類“Doctrine \\ ORM \\ Persisters \\ ManyToManyPersister”
當我刪除與他們一起保存的所有子表單項時,會發生這種情 至少留下一個不會發生錯誤。 此外,如果我最初保存沒有孩子的實體一切正常。
/**
* West\AlbumBundle\Entity\Album
*
* @ORM\Table(name="albums")
* @ORM\Entity(repositoryClass="West\AlbumBundle\Entity\AlbumRepository")
* @ORM\HasLifecycleCallbacks
*/
class Album extends Entity implements CrudEntity
{
/**
* @ORM\ManyToMany(targetEntity="Album")
* @ORM\JoinTable(name="albums_relations",
* joinColumns={@ORM\JoinColumn(name="album_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="related_album_id", referencedColumnName="id")}
* )
* @var ArrayCollection
*/
protected $related_albums;
}
如果您正在使用Symfony2表單進行測試,請記住設置
“by_reference”=> false
我發現當調用UnitOfWork.scheduleCollectionDeletion方法時會出現問題,例如,從MergeDoctrineCollectionListener.onBind()調用並且已克隆PersistentCollection對象('by_reference'= false)
快速解決此問題的方法是在MergeDoctrineCollectionListener類中注釋以下行:
//$collection->clear();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.