Search code examples
phpdoctrine-ormdql

Doctrine\ORM\Query\QueryException - Error: Expected end of string, got 'WHERE'


There is a function I'm using to get next photo in gallery:

$q = "SELECT i FROM GalleryModule\Image i WHERE i.id = (SELECT MIN(p.id) FROM GalleryModule\Image p WHERE p.id > :id ORDER BY p.position, p.id DESC) WHERE i.gallery = :gallery";
    $query = $this->getEntityManager()->createQuery($q);
    $query->setMaxResults(1);
    $query->setParameters(array(
        'id' => $image->getId(),
        'gallery' => $image->getGallery()->getId()
    ));
    return $query->getOneOrNullResult();

The error I'm still facing:

Doctrine\ORM\Query\QueryException

[Syntax Error] line 0, col 143: Error: Expected end of string, got 'WHERE'

Thanks a lot in advance.


Solution

  • You have multiple where's

    Perhaps u mean this:

    SELECT i FROM GalleryModule\Image i 
    WHERE i.id = 
        (SELECT MIN(p.id) 
        FROM GalleryModule\Image p 
        WHERE p.id > :id ORDER BY p.position, p.id DESC) 
    AND i.gallery = :gallery