我准备了一个满足我要求的 sql 语句,但我需要将该 sql 语句转换为 cakePHP 模型查找条件我不知道如何准备那个请帮助我
SQL查询:
select id,text,is_file,order from kmp_contents
where parent_id=1873
order by case
when is_file=1 then text
when is_file=0 then order
end asc;
你可以试试:
$this->KmpContent->find(
'conditions' => array('KmpContent.parent_id' => 1873),
'fields' => array('KmpContent.id', 'KmpContent.text', 'KmpContent.is_file', 'KmpContent.order'),
'order' => array('KmpContent.case ASC', 'WHEN is_file=1 THEN KmpContent.text WHEN is_file=0 THEN KmpContent.order ASC')
);
键将提供的数组中提供的order
条件包装在ORDER BY
语句周围。
如果这不起作用,您始终可以Model::query()
用于复杂查询。