本文介绍了使用fetch-joined集合限制一个原则查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个教条查询返回博客文章及其评论:

I have a doctrine query that returns blog posts and their comments:

SELECT b, c FROM BlogPost b LEFT JOIN b.comments c

我想将结果限制为10个博文。根据DQL文档, setMaxResults()在获取加入集合的查询(在本例中为注释))无法正常工作:

I would like to limit the results to 10 blog posts. According to the DQL documentation, setMaxResults() doesn't work correctly on queries that fetch-join a collection (comments in this case):

如何正确地限制包含fetch-joined的原则查询收集(在这种情况下,将结果限制为10个博客帖子)?

How would I properly limit a doctrine query that contains a fetch-joined collection (in this case, limit the results to 10 blog posts)?

推荐答案

分页符合原则2.2和新的symfony2版本2.0.10兼容。

Paginate was merged with doctrine 2.2 And the new symfony2 release 2.0.10 is compatible with.

现在使用它像

//use Doctrine paginator
use Doctrine\ORM\Tools\Pagination\Paginator;

编写您的查询,然后调用结果。

Write your query then call results like that.

$query->setMaxResults($limit);
$query->setFirstResult($offset);
$results = new Paginator($query, $fetchJoin = true);

希望这将有助于您。

注意:如果您使用的是SF2 2.0.10,则应更新deps和deps.lock文件,并为Doctrine软件包指定2.2版本。

Note: If you are using SF2 2.0.10, you should update the deps and deps.lock files and specify the 2.2 version for Doctrine bundles.

这篇关于使用fetch-joined集合限制一个原则查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 12:46