Question

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

Was it helpful?

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.

OTHER TIPS

I think the shortest way can be:

Doctrine_Query::create()->select()->from('MyTable')->limit(5)->execute();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top