2

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! :-)

Philippe Gerber
  • 17,457
  • 6
  • 45
  • 40

2 Answers2

2

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.

Nowhere man
  • 5,007
  • 3
  • 28
  • 44
1

I think the shortest way can be:

Doctrine_Query::create()->select()->from('MyTable')->limit(5)->execute();
JMax
  • 26,109
  • 12
  • 69
  • 88
rickart
  • 11
  • 2