I have a problem using entityManager->createQuery() in my repository class.
public function findAllByDateAndUser( \DateTime $from, \DateTime $to, User $user ) {
return $this->getEntityManager()->createQuery(
'SELECT wu, a, ai
FROM ArpanetCompanyWorkBundle:WorkerUsage wu
JOIN ArpanetCompanyWorkBundle:AttendanceItem ai WITH ( wu.attendanceItem = ai )
JOIN ArpanetCompanyWorkBundle:Attendance a WITH ( ai.attendance = a )
WHERE wu.user = :userP
AND WHERE a.date >= :fromP
AND WHERE a.date <= :toP'
)
->setParameter( 'userP', $user )
->setParameter( 'fromP', $from )
->setParameter( 'toP', $to )
->getResult();
}
I got an error:
[2/2] QueryException: [Syntax Error] line 0, col 344: Error: Expected Literal, got 'WHERE'
Where is the problem?
I know it can be done by using query builder, but I need to get all entities by one database query because of performance reasons.
The problem was in using AND WHERE
instead of only AND
.