How to add statements to the doctrine2 query constructor, where the statement

I am trying to choose from a table where the selected duration divided by the recording duration is zero.

$qb = $em->createQueryBuilder()
->from('AcmeBlogBundle:Entry', 'e')
->andWhere(":duration % e.duration = 0")
->setParameter('duration', $duration);

This returns an error:

[Syntax Error] line 0, col 226: Error: Expected =, <, <=, <>, >, >=, !=, got '%' 

This will work in plain SQL. Does anyone know how to do this with the Doctrine query constructor?

+5
source share
1 answer

A character is %not a DQL statement. Try the following:

$qb = $em->createQueryBuilder()
->from('AcmeBlogBundle:Entry', 'e')
->andWhere("mod(:duration,e.duration) = 0")
->setParameter('duration', $duration);

Or read this: http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/dql-doctrine-query-language.html Section 12.5.1.

MOD(a, b) - Return a MOD b.
+9
source

All Articles