I have a data transformer where I am trying to check for duplicates in my tagging system.
Code:
use Doctrine\Common\Persistence\ObjectManager; use Symfony\Component\Form\DataTransformerInterface; use Doctrine\Common\Collections\ArrayCollection; class TagsToCollectionTransformer implements DataTransformerInterface { private $manager; public function __construct(ObjectManager $manager) { $this->manager = $manager; } public function transform($tags) { return $tags; } public function reverseTransform($tags) { $tagCollection = new ArrayCollection(); $tagsRepository = $this->manager->getRepository('MyThorluxBundle:Tag'); foreach ($tags as $tag) { $tagInRepo = $tagsRepository->findBy(['name' => $tag->getName(); if ($tagInRepo !== null) { // Add tag from repository if found $tagCollection->add($tagInRepo); } else { // Otherwise add new tag $tagCollection->add($tag); } } return $tagCollection; } } I have changed the findOneByname method to the FindBy shown above however I cannot access any of the methods of $tag even though I get the repository. I should be able to call getname() on $tag yet it cannot find the method?
Thanks.
findBy(['name' => $tag->getName()])