Search code examples
phpdoctrinedqlnamed-query

Doctrine Named Queries: Specifing limit on query call


Let's imagine something like this:

class MyTable extends Doctrine_Table
{
    public function construct()
    {
        $q = Doctrine_Query::create()->from('MyTable t')
                                     ->orderBy('t.creationDate DESC')
                                     ->limit(5);
        $this->addNamedQuery('top5', $q);
    }
}

Later I can do something like this:

$top5 = Doctrine::getTable('MyTable')->find('top5');

Is there any way I can set the limit when using the named query, and not when defining it? I'd would really love to do something like:

$top5 = Doctrine::getTable('MyTable')->find('topX', 5);

or

$top5 = Doctrine::getTable('MyTable')->find('topX', array('limit' => 5));

Thx in advance! :-)


Solution

  • Nothing prevents you from writing your own method or function that clones the named unlimited query, sets a limit on the clone and then returns results.