I got problems with persisting many to many self referencing relations. I receive error:
The class 'Doctrine\ORM\Persisters\ManyToManyPersister' was not found in the chain configured namespaces
This happens when I remove all children form item saved with them. Leaving at least one don't make error happen. Also if I initially save entity with no children everything works fine.
/**
* 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;
}
If you're testing with Symfony2 forms remember to set
"by_reference" => false
I've found that the problem happens when the method UnitOfWork.scheduleCollectionDeletion is called, for example, from MergeDoctrineCollectionListener.onBind() and the PersistentCollection object has been cloned ( 'by_reference' = false )
A quick fix to this problem is to comment the following line in the MergeDoctrineCollectionListener class:
//$collection->clear();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With