Skip to content

Instantly share code, notes, and snippets.

@oste
Last active December 17, 2015 02:59
Show Gist options
  • Save oste/5540302 to your computer and use it in GitHub Desktop.
Save oste/5540302 to your computer and use it in GitHub Desktop.
remove all relating entities from entity
$post = $postManager->findOneBy(['id' => $id]);
//each post has many categories
//how can I remove any existing relationships from the rel table?
$post->removeCategories();
/**
* @ORM\Table(name="post")
* @ORM\Entity
*/
class Post
{
/**
* @ORM\ManyToMany(targetEntity="Category", inversedBy="posts")
* @ORM\JoinTable(name="post_categories_rel")
*/
protected $categories;
public function __construct()
{
$this->categories = new ArrayCollection();
}
public function removeCategories()
{
//how should this look?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment