CakePHP连接查询与concat

时间:2012-09-14 07:34:03

标签: cakephp concat

我需要帮助在CakePHP中运行此查询,我无法阅读文档。查询必须匹配此查询

SELECT 
    form_number, 
    code_b, 
    local_governments.lga, 
    local_governments.code, 
    concat(local_governments.code,code_b)  
FROM 
    `applicants` 
        left join local_governments 
            on applicants.local_government_id=local_governments.id 
where 
    printed=0

1 个答案:

答案 0 :(得分:0)

我将假设您的模型设置正确并且也正确关联。

$applicants = $this->Applicant->find('all', 
    array(
        'conditions' => array(
            'Applicant.printed' =>  0,
        ),
        'contain' => array('LocalGovernment'),
        'fields' => array(
            'Applicant.form_number', 
            'Applicant.code_b', 
            'LocalGovernment.lga', 
            'LocalGovernment.code', 
        )
    )
);

至于你的联合...只是在视图中显示值时这样做。

我希望这有帮助......让我知道。