I’ve been strugling with those feature (attach/merge feature).
My need is simple, I have a BookFilterType which filters a collection of Book object.
Until now, when doing
public function indexAction()
{
$book = new Book($this->getUser());
$filters = $this->getFilters();
$form = $this->createForm(new BookFilterType(), $filters);
...
return array(...);
}
I got an error : Entities passed to the choice field must be managed because in the filter they were others entities.
So basically, i needed to store only ID’s when saving the filters criterias in the session, and then re-hydrate them using find($id).
But this is ugly, and my code gets unreadable !
So i’ve decided to go with the detach / merge feature.
After storing detached entities i want to merge them again to re-inject values in the form, it seems that I need to use cascade={"merge"} on my Object because i get :
Class Doctrine\Common\Collections\ArrayCollection is not a valid entity or mapped super class.
THE QUESTION (finally)
Where do i put the cascade={"merge"} : On the joinColumns OR inverseJoinColumns ? or BOTH ? ? Cause I have only ManyToMany associations in those filters
/**
* @ORM\ManyToMany(targetEntity="MyTargetedEntity")
* @ORM\JoinTable(name="target_entity_nn",
* joinColumns={@ORM\JoinColumn(name="some_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="other_id", referencedColumnName="id")}
* )
*
**/
private $contributors;
PS: i’m using Symfony2.1 / Doctrine master.
Thanks
You can put it on the @ORM\ManyToMany
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#manytomany