11

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

Maciej Pyszyński
  • 9,266
  • 3
  • 25
  • 28

1 Answers1

2

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();
dagaren
  • 21
  • 3
  • 1
    Shouldn't be commenting out vendor code as it will prevent you in the future from receiving updates through composer. If you wanted to do this neatly you could fork Doctrine's repo, make the change and your fork. That way you could maintain a fork of Doctrine and still be able to pull upstream from Doctrine to keep up to date with the latest codebase. Commenting out that line could have other unforseen changes in Doctrine's behaviour so I'd treat it as experimental at best. – Bendihossan Nov 20 '12 at 09:18