W
W
WebDev2015-03-06 16:48:28
PHP
WebDev, 2015-03-06 16:48:28

Limit in Doctrine2?

Hello. There is a request like this:

$qb = $this->getEntityManager()->createQueryBuilder();
        $qb->select('Activity')
                ->from($this->_entityName, 'Activity')
                ->leftJoin('Activity.patterns', 'Pattern')
                ->leftJoin('Pattern.metas', 'Meta')
                ->leftJoin('Pattern.pickups', 'Pickup')
                ->leftJoin('Activity.duration', 'Duration')
                ->andWhere(':timestapmStart >= Meta.repeat_start')
                ->andWhere(':timestapmStart <= Meta.repeat_end')
                ->andWhere(':timestapmEnd >= Meta.repeat_start')
                ->andWhere(':timestapmEnd <= (Meta.repeat_end + '.($interval*24*60*60).')')
                ->andWhere('Pickup.city = :city')
                ->setParameter('timestapmStart', $date->getTimestamp())
                ->setParameter('timestapmEnd', $dateEnd->getTimestamp())
                ->setParameter('city', $city);

Then you need to set a limit.
I use paginator:
$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($qb, true);
        $result = $paginator->getQuery()
                            ->setMaxResults(3)
                            ->getResult();

As a result, one record is returned. Also no paginator. And if I specify a limit of 3-6, then 2 records are returned, 7-10 - 3 records, and so on. The point, as I understand it, is in joins, if you disable all joins and conditions, then it works as it should. Help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RJs45, 2015-03-12
@RJs45

Do you have a limit-only paginator, or do you really need pagination? For limits, QueryBuilder has

->setFirstResult( $offset )
->setMaxResults( $limit );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question