'[Syntax Error] line 0, col 71: Error: Expected end of string, got 'LIMIT''
Here's my code:
public function getLatestChapters()
{
return $this->_em->createQuery('SELECT c, m FROM models\Chapter c JOIN c.Manga m ORDER BY c.CreateDate LIMIT 10')->getResult();
}
What could posibly the problem for this? How can I use LIMIT in Doctrine?
I am using Doctrine 2
Seems like there is no LIMIT/OFFSET in DQL anymore.
$qb = $em->createQueryBuilder();
//.. build your query
$q = $qb->getQuery();
$q->setFirstResult($offset);
$q->setMaxResults($limit);
$result = $q->getResult();
I would Like to Contribute to this post and want to tell people that If you want to use DBAL with limit in your Unit Tests you can use following:
$client = static::createClient()
$em = $client->getContainer()->get('doctrine')->getManager();
$query = $em->createQuery('WRITE YOUR QUERY HERE');
$query->setFirstResult(0);
$query->setMaxResults(1);
$data = $query->getResult();
Same code can be used in controller also with some modifications :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With