我只想返回用户表中的所有行,但返回选定的字段,以及可能的concat 2字段。
正常的sql可能只是:
SELECT id, CONCAT(`first_name`,`last_name`) AS `fullname` FROM `users`
但试图在蛋糕中实现这一点是一场噩梦:
$users = $this->User->find("all") = returns everything
$users = $this->User->find("list",array("fields" => " ...) does not work either.
有人能帮助我如何使用蛋糕模型来实现简单的查询和返回结果
您已接近:
$this->User->find('all', array('fields' => array('CONCAT(first_name,last_name) AS fullname', 'otherfield'), 'contain' => array());