Search code examples
codeigniterdoctrine-orm

doctrine query language(DQL) createquery with LIMIT


how to use LIMIT on DQL,

i have dql like this

$LampuOns = self::$em->createQuery("SELECT c FROM \Entities\Product\Category c WHERE id='{$Dataid}'")->execute();

when i added limit like this

$LampuOns = self::$em->createQuery("SELECT c FROM \Entities\Product\Category c WHERE id='{$Dataid}' LIMIT = 1")->execute();

it returned error message. any have idea please?


Solution

  • DQL Don't implement any limit clausole, look at this issue for motivation.

    So you must use the Doctrine Query::setMaxResults()

    So somethings like:

    $LampuOns = self::$em->createQuery("SELECT c FROM \Entities\Product\Category c WHERE id='{$Dataid}'");
    $LampuOns->setMaxResult(1);
    $LampuOns->execute();
    

    Hope this help