Reputation: 31919
Option 1
and Option 2
seem to give similar results. Is there a particular advantage for using the execute statement
rather than the usual getResult()
method?
public function getEventsByOrganiser(EventInterface $event, $username)
{
$qb = $this->repository->createQueryBuilder('e')
->select(array('e', 'u'))
->leftJoin('e.user', 'u')
->andWhere('u.username = :username');
return $qb->getQuery()->execute(array(
'username' => $username
));
}
public function getEventsByOrganiser(EventInterface $event, $username)
{
$qb = $this->repository->createQueryBuilder('e')
->select(array('e', 'u'))
->leftJoin('e.user', 'u')
->andWhere('u.username = :username')
->setParameter('username', $username);
return $qb->getQuery()->getResult();
}
Upvotes: 10
Views: 6677
Reputation: 3393
Basically getResult()
is alias for execute(array())
you can set as argument hydration mode for example: getResult(Query::HYDRATE_OBJECT)
is execute(array(), Query::HYDRTE_OBJECT)
Only difference: in execute method you can set query parameters as first argument so you do not have to call setParameter
method before...
Upvotes: 15