在使用CakePHP中的GROUP BY進行分頁時,結果數量不正確。這是一個記錄的項目爲是(是)可以預期的,但根據this page in the CakePHP book:在CakePHP 2.0+中使用Group By進行分頁
在CakePHP 2.0,你不再需要實現paginateCount()時使用 組條款。核心查找('count')將正確計算總行數 。
我使用CakePHP 2.2.3,但我仍然有問題。有什麼具體的我需要做的?我誤解了陳述嗎?我是否還需要使用自定義分頁()和/或paginateCount方法?
的「計數不正確」澄清:我加入表1瓦特/表2 - 所以,即使我只有一個「表1項目」,它檢索2行......但後來我按到的ID table1項目,它只返回1個項目。然而,計數顯示「2找到」,但只顯示1個項目。
更新:(代碼)
$this->Paginator->settings = array(
'limit' => (int) 20,
'conditions' => array(
(int) 0 => array(
'Article.node_type_id' => '5050ede8-3f88-45f4-b58f-1130d9d84497'
),
(int) 1 => array(
'OR' => array(
'DataText.title LIKE' => '%john%',
'Article.name LIKE' => '%john%'
)
)
),
'order' => array(
'Article.created' => 'DESC'
),
'fields' => array(),
'joins' => array(
(int) 0 => array(
'table' => 'data_texts',
'alias' => 'DataText',
'type' => 'INNER',
'conditions' => array(
(int) 0 => 'DataText.node_id = Article.id'
)
)
),
'contain' => array(
'Slug' => array(
'order' => array(
(int) 0 => 'FIELD(Slug.language_id, "c141eafd-567a-4bc5-badd-c5a163c01f46") DESC'
)
),
'NodeType' => array(
'ChildNodeType' => array()
),
'DataLocation' => array(
'conditions' => array()
),
'DataMeta' => array(
'conditions' => array()
)
),
'group' => 'Article.id'
)
PAGINATE稱自己:
$nodes = $this->paginate($model);
你可以用paginate()函數發佈你正在做的調用嗎? – elpeter
Pedro - 添加了我的代碼。 – Dave