我用leftJoin请求获取这些品牌的所有品牌和所有项目:
$brands = Doctrine_Query::create()
->from('Brand b')
->leftJoin('b.Item i')
->fetchArray();但是我只想要每个品牌的10件商品,我怎么才能限制商品leftJoin呢?
发布于 2012-08-21 18:55:20
您必须像这样使用子查询:
->leftJoin('b.Item i WITH i.id IN (SELECT i2.id FROM Item i2 WHERE i2.brand_id=b.id LIMIT 10)')我没有对此进行测试,但它应该可以工作。
发布于 2013-05-31 19:26:48
我知道为时已晚,但这实际上在我的谷歌搜索中得了nr 1,没有人回答:Limiting a doctrine query with a fetch-joined collection?建议使用Paginaror对象
下面是一个示例:
我的代码的源代码包含rss链接和rss提要中的文章。所以在这个例子中,我将获得一个源代码和所有的文章。
// get the articles (latest first) from source 743
$q=$this->getDoctrine()->getManager()
->createQuery('select s, a from MyCompanyRssBundle:Source s
join s.Articles a
where s.id = :id
order by a.id desc')
->setParameter('id',743);
$q->setMaxResults(1); // this limits Articles to be only 1
// when using $q->getResult();
$sources=new Paginator($q, $fetchJoin = true);
$sources=$sources->getIterator();
// $sources=$q->getResult();
var_dump($sources[0]->getArticles());https://stackoverflow.com/questions/12037010
复制相似问题