Guest User

CakePHP 2.0 Retrieve Aggregate function inner Containable

a guest
Nov 24th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. $this->PollingText->Behaviors->load('Containable', array('autoFields' => false));
  2. $pollings = $this->PollingText->find('all', array(
  3.     'conditions' => array('PollingText.polling_category_id' => $category_id),
  4.     'order' => array('PollingText.order_number' => 'ASC'),
  5.     'contain' => array(
  6.         'PollingQuestion',
  7.     'PollingQuestion.PollingAnswer',
  8.     'PollingQuestion.PollingAnswer.Respondent' => array(
  9.         'conditions' => array(
  10.             'Respondent.created BETWEEN ? AND ?' => array(
  11.                 $startDate->format('Y-m-d'),
  12.             $endDate->format('Y-m-d')
  13.                 ),
  14.             ),
  15.         'group' => array('Respondent.created'),
  16.             'fields' => array(
  17.                 'COUNT(Respondent.id) AS total_respondent',
  18.                 'Respondent.created'
  19.             )
  20.         ),
  21.     ),
  22. ));
  23.  
Advertisement
Add Comment
Please, Sign In to add comment