Hello friends I am new to Cakephp 2.6, I need to convert MySql query to Cakephp 2.6 . I am getting the desired output, I am fetching the last conversation between client and consultant group by task ID. I don't want to write the Model:query() as I need default pagination of cakephp too.
This is my following table, please have a look
SELECT * FROM (SELECT task_id, MAX(created) AS created FROM task_conversations GROUP BY task_id) AS x
JOIN task_conversations USING (task_id, created)
WHERE (client_id=3 OR consultant_id= 3) ORDER BY modified ASC
This is the following output of the above query:
I am trying to resolve it by writing the following lines of code
$this->paginate = array(
'conditions' => array(
'TaskConversation.sender_id' => $consultant['User']['id'],
'Task.status' => 1
),
'group' => 'TaskConversation.task_id',
'limit' => 3,
'order' => array('TaskConversation.conversation'=> 'ASC'
),
'recursive' => 2
);
$this->set('tasks', $this->Paginator->paginate());
I will require the pagination too here. Please let me know your feedback. Thanks in advance


Finally I got the solution for it. Here is the solution:
I have added custom pagination functions in Model. Here is the code:
In the controller I have added the following lines:
If you don't want to use custom pagination in other function related with same model then I have passed this in paginate 'isCustomPagination' => 0.