More likely an old post, but wanted to provide a way to ensure that the association was removed from the ORM Entity side of the doctrine, instead of manually executing each remove Entity element and extending the answer to @Rene Terstegen.
The problem is that Doctrine does not "automatically-magically" associate associations, however you can update the methods for adding / removing entities for this.
https://gist.github.com/Ocramius/3121916
The following example is based on the project design / OP category. The project_category table is assumed to be a ManyToMany relationship ManyToMany , and the project and category tables use the primary key id .
class Project { protected $categories; public function __construct() { $this->categories = new ArrayCollection(); } public function removeCategory(Category $category) { if (!$this->categories->contains($category)) { return; } $this->categories->removeElement($category); $category->removeProject($this); } }
class Category { protected $projects; public function __construct() { $this->projects = new ArrayCollection(); } public function removeProject(Project $project) { if (!$this->projects->contains($project)) { return; } $this->projects->removeElement($project); $project->removeCategory($this); } }
Then you just need to call the removeCategory or removeProject , not both. The same can be applied to addCategory and addProject .
$project = $em->find('Entities\Project', $projectId); $category = $em->getReference('Entities\Category', $categoryId); $project->removeCategory($category); $em->flush();
fyrye source share