在CakePHP中使用别名和order by

时间:2015-07-09 15:03:19

标签: cakephp select alias

我需要创建一个带别名的选择,如下所示:

SELECT*, (adresses.v1 + adresses.v2) AS total FROM adresses ORDER BY distance DESC

如何在下面的代码中插入此查询?

$objects = $this->Property->find('all', array(
    'recursive' => 2,
    'reformat' => true,
    'conditions' => $conditions,
    'order' => $order,
    'joins' => $joins,
));

1 个答案:

答案 0 :(得分:1)

Try:
$objects = $this->Property->find('all', array(
    'recursive' => 2,
    'reformat' => true,
    'conditions' => $conditions,
    'order' => $order,
    'joins' => $joins,
    'fields' => array('*', '(adresses.v1 + adresses.v2) AS total'),
));