其实如果你可以做到这一点,你可以用paginate做到这一点。你可以看看here
但更具体一点,你可以添加条件/限制/领域/包含/订单等你在查找使用paginate函数。
我没有使用组在PAGINATE但它应该工作:d
你的情况,你就会有这样的事情:
$this->paginate = array(
'fields' => array(
'Product.category_id',
'COUNT(Product.hotel_id) as total'
),
'group' => array(
'Product.category_id HAVING COUNT(Product.hotel_id) > 1')
)
);
$data = $this->paginate('Product');
希望工程,发表您的结果的评论,如果它不起作用,你将不得不重写它,因为它不接受组条件......虽然我认为它会起作用,因为分页是最终的发现。
编辑:
你可以尝试做这样的事情:
覆盖的PAGINATE()和paginateCount(),但有一个调整,偷偷的条件,所以你可以告诉我们,如果它是一个分页具有或不。事情是这样的:
function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()){
//if no having conditions set return the parent paginate
if (empty($conditions['having'])
return parent::paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra)
//if having conditions set return your override
//override code here
}
那么你就在paginateCount类似的东西(),这样你有选择性PAGINATE。请记住在不需要时设置$ conditions ['having'],或者记住将它放在某个不会影响您的搜索的地方;)
这是一个有趣的解决方案,但不幸的是打破了paginateCount(),因为缺少名为“分数”的列。 –
+1用于通过字符串窃取组中的“HAVING”子句。但是当你复印时,请照顾那些丑陋的卷曲报价。 – Johan
对不起,感谢编辑 @TomWright嗯,这是真的,我想,你必须重写paginateCount()函数,在[book](http:// book)中读取更多的自定义查询。 cakephp.org/view/249/Custom-Query-Pagination)我发现你确实需要覆盖至少paginateCount();但是你可以做一些事情来区分使用哪一种,我在我的答案 – api55