Doctrine 命名查询:指定查询调用的限制

发布于 2024-07-25 22:33:52 字数 745 浏览 3 评论 0原文

让我们想象一下这样的事情:

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);
    }
}

稍后我可以做这样的事情:

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

有什么方法可以在使用命名查询时设置限制,而不是在定义它时设置限制? 我真的很想做一些类似的事情:

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

或者

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

提前谢谢! :-)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水水月牙 2024-08-01 22:33:52

没有什么可以阻止您编写自己的方法或函数来克隆命名的无限查询,对克隆设置限制,然后返回结果。

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.

挽袖吟 2024-08-01 22:33:52

我认为最短的方法可以是:

Doctrine_Query::create()->select()->from('MyTable')->limit(5)->execute();

I think the shortest way can be:

Doctrine_Query::create()->select()->from('MyTable')->limit(5)->execute();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文