在 CakePHP 中使用 order by 的别名
Use alias with order by in CakePHP
我需要用别名创建一个 select,像这样:
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,
));
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'),
));
我需要用别名创建一个 select,像这样:
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,
));
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'),
));