Details
Description
I have an entity with a many-to-many relation.
When I delete all relations and then flush, add new relations and then flush, all inside one transaction, I get
Fatal error: Call to a member function update() on a non-object in Doctrine/ORM/UnitOfWork.php on line 312
// Delete old categories foreach ($revision->getCategories() as $category) { $revision->removeCategory($category); } $this->entityManager->flush(); // Add new foreach ($categories as $categoryId) { $category = $this->entityManager->find('Category', $categoryId); if ($category instanceof Category) { $revision->addCategory($category); } } $this->entityManager->flush();
Revision::getCategories()
/**
* @return ArrayCollection
*/
public function getCategories()
{
return $this->categories;
}
Revision::addCategory()
/**
* @param Category $category
* @return Revision
*/
public function addCategory(Category $category)
{
$this->categories->add($category);
return $this;
}
Revision::removeCategory()
/**
* @param Category $category
* @return Revision
*/
public function removeCategory(Category $category)
{
$this->categories->removeElement($category);
return $this;
}
If this is not a bug, I'd like to know which is the most efficient and elegant way to update many-to-many relationships.
Issue Links
- is duplicated by
-
DDC-839
Error when trying to update PersistentCollection
-