Gaylord.P
Gaylord.P

Reputation: 1468

NativeQuery, join and Limit

I'm using "NativeQuery" with Doctrine and my query has an INNER JOIN. I want to do "Limit" with only the first table for the results. But, In Mysql, "Limit" takes into account joined tables. Any idea on how to achieve this? Thanks

Upvotes: 0

Views: 116

Answers (2)

king-il
king-il

Reputation: 29

here is an example with QueryBuilder you can adapt it to you own usage

$qb = $this->createQueryBuilder('a');

$qb
  ->join('a.advert', 'adv')
  ->addSelect('adv')
;


$qb->setMaxResults($limit);


return $qb
  ->getQuery()
  ->getResult()
  ;

you've said you are french here is a good tutorial
Récupérer ses entités avec Doctrine2

Upvotes: 0

abdiel
abdiel

Reputation: 2106

I think that you are looking for Doctrine Pagination. http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/tutorials/pagination.html

Upvotes: 1

Related Questions