Doctrine2: check if exists value in Doctrine Collection Doctrine2: check if exists value in Doctrine Collection symfony symfony

Doctrine2: check if exists value in Doctrine Collection


You could do:

$object = $this->getDoctrine()->getRepository('MyBundle:MyClass')->find($id);if ( !$entity->getMyCollectionValues()->contains($object) ) {    $entity->addMyCollectionValue($object);}

You could look at the available functions of Doctrine ArrayCollection in http://www.doctrine-project.org/api/common/2.1/class-Doctrine.Common.Collections.ArrayCollection.html