实际上,如果你可以用 find 来做到这一点,你也可以用 paginate 来做到。你可以看一下here
但更具体地说,您可以将查找中使用的条件/限制/字段/包含/顺序等添加到分页函数中。
我没有在分页中使用组,但它应该可以工作: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');
希望它有效,对你的结果发表评论,如果它不起作用,你将不得不覆盖它,因为它不接受组条件......尽管我认为它会起作用,因为分页最终是一个发现。
EDIT:
你可以尝试做这样的事情:
覆盖 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() 中做类似的事情,这样你就可以进行选择性分页。记住在不需要时取消设置 $conditions['having'] 或记住将其放在不影响您的查找的地方;)