Doctrine 命名查询:指定查询调用的限制
让我们想象一下这样的事情:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.
我认为最短的方法可以是:
I think the shortest way can be: