Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created May 16, 2012 02:10
Show Gist options
  • Save violetyk/2706745 to your computer and use it in GitHub Desktop.
Save violetyk/2706745 to your computer and use it in GitHub Desktop.
[cakephp]Model::find()でcountとかsumとか上手くとる方法
<?php
$this->SurveyResponse->virtualFields['count'] = 0;
$data = $this->SurveyResponse->find(
'all',
array(
'fields' => array(
'SurveyResponse.response_value',
'count(id) as "SurveyResponse__count"',
),
'conditions' => array(
'SurveyResponse.survey_question_id' => $survey_question_id,
),
'group' => array('SurveyResponse.response_value'),
'recursive' => -1,
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment