Skip to content

Instantly share code, notes, and snippets.

@nicosomb
Last active August 29, 2015 14:16
Show Gist options
  • Save nicosomb/baf9e975ab60d12f7404 to your computer and use it in GitHub Desktop.
Save nicosomb/baf9e975ab60d12f7404 to your computer and use it in GitHub Desktop.
relation entry <-> tags
<?php
$qb = $this->createQueryBuilder('e')
->leftJoin('e.tags', 't')
->addSelect('t')
->where('e.id = t.entry_id')
->setMaxResults(1);
<?php
// mon test
$entry = $client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->findOneWithTags();
$entry->getTags(); // --> Call to a member function getTags() on a non-object
// mon repository
public function findOneWithTags()
{
$qb = $this->createQueryBuilder('e')
->innerJoin('e.tags', 't')
->addSelect('t')
->setMaxResults(1);
return $qb
->getQuery()
->getResult();
}
// mon entité Entry
// ...
/**
* @return ArrayCollection<Tag>
*/
public function getTags()
{
return $this->tags;
}
@Gregoire-M
Copy link

Juste ça, ça suffit pas ?

<?php
$qb = $this->createQueryBuilder('e')
        ->innetJoin('e.tags', 't')
        ->addSelect('t')
        ->setMaxResults(1);

@nicosomb
Copy link
Author

innetJoin ? connais pas ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment