I have the following Gallery entity
class Gallery
{
/**
* @var integer
*
* @ORM\\Column(name=\"id\", type=\"integer\")
* @ORM\\Id
There is article in Symfony2 cookbook about handling this type of situation. As you have OneToMany relationship, you have to remove related objects manually in controller.
Edit: Or you can make use of Doctrine's orphan removal feature.
class Gallery
{
//...
/**
* @ORM\OneToMany(targetEntity="Photo", mappedBy="gallery", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $photos;
//...
public function removePhotos($photo)
{
$this->photos->remove($photo);
$photo->setGallery(null);
}
}