原则\ORM\查询\查询异常 - 错误:字符串的预期结尾,已'WHERE'



我正在使用一个函数来获取画廊中的下一张照片:

$q = "SELECT i FROM GalleryModuleImage i WHERE i.id = (SELECT MIN(p.id) FROM GalleryModuleImage 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();

我仍然面临的错误:

DoctrineORMQueryQueryException

[语法错误]line 0, col 143: Error: Expected end of string, got 'WHERE'

你有多个where's

也许你是这个意思:

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

相关内容

  • 没有找到相关文章

最新更新