2014-10-05 12 views
0

케이크 PHP 코드 -어떻게 구현 "합 케이스를 가진 경우"CakePHP의에서

$this->paginate = array(
    'Lead' => array(
     'joins'=>array(
       array(
        'type'=>'left', 
        'table'=>'lead_countries', 
        'alias'=>'LeadCountry', 
        'conditions'=>array(
         'LeadCountry.lead_id = Lead.id', 
        ), 

       ) 
      ), 
     'conditions' => $conditions, 
     'order' => array('LeadCountry.lead_id' => 'DESC'), 
     'group' => array('LeadCountry.lead_id'), //fields to GROUP BY    
     'limit' => $per_page 
    ) 
); 
$leads = $this->Paginator->paginate('Lead'); 
$this->set(compact('leads')); 

그것은 MySQL의 쿼리에게의

SELECT `Lead`.`id` , `LeadCountry`.`primary_email` , `LeadCountry`.`first_name` , `LeadCountry`.`lead_id` , `LeadCountry`.`id` 
FROM `leads` AS `Lead` 
INNER JOIN `ekowarehouse`.`lead_countries` AS `LeadCountry` ON (`LeadCountry`.`lead_id` = `Lead`.`id`) 
GROUP BY `Lead`.`id` 
HAVING sum(
CASE WHEN `LeadCountry`.`active` <>0 
THEN 1 
ELSE 0 
END) =0 

위 케이크 PHP 코드에서이 섹션 아래에 구현하는 방법

HAVING sum(
CASE WHEN `LeadCountry`.`active` <>0 
THEN 1 
ELSE 0 
END) =0 

in cake php

답변

0

cakephp에서 "sum case with when"구현하기

$this->paginate = array(
    'Lead' => array(
     'joins'=>array(
       array(
        'type'=>'left', 
        'table'=>'lead_countries', 
        'alias'=>'LeadCountry', 
        'conditions'=>array(
         'LeadCountry.lead_id = Lead.id', 
        ), 

       ) 
      ), 
     'conditions' => $conditions, 
     'order' => array('LeadCountry.lead_id' => 'DESC'), 
     //'group' => array('LeadCountry.LeadCountry'), //fields to GROUP BY 
     'group' => '`LeadCountry`.`LeadCountry` HAVING sum(case when `LeadCountry`.`active` <> 0 then 1 else 0 end) = 0', //fields to GROUP BY    
     'limit' => $per_page 
    ) 
); 
$leads = $this->Paginator->paginate('Lead'); 
$this->set(compact('leads'));