You need to put them in a loop and delete each
foreach ($comments as $cm) { $em->remove($cm); } $em->flush();
Just in case for the future, if you have a OneToMany relationship for the field and you want to delete all related objects with this or a specific object in the collection, you can try
//entity class /** * @ORM\OneToMany(targetEntity="Target_Entity_Class",mappedBy="mapped_property") * @var ArrayCollection */ $objects; //... public function removeObject(\Name\Space\To\Target\Entity $target) { $this->objects->removeElement($target); }
And in your controller you can say
// assume $removed_objects_list is an array of related objects which you want to remove $target_object = $em->getRepository('TargetEntity')->find($target_id); foreach ($removed_objects_list as $object) { $target_object->removeObject($object); } $em->flush();
Javad source share