Reputation: 3592
I simply want to return all rows from a users table but selected fields, and possible concat 2 fields.
normal sql could have just been:
SELECT id, CONCAT(`first_name`,`last_name`) AS `fullname` FROM `users`
But trying to achieve this in cake is a nightmare:
$users = $this->User->find("all") = returns everything
$users = $this->User->find("list",array("fields" => " ...) does not work either.
Can anyone please help me on how to use the cake model to achieve the simple query and return results
Upvotes: 0
Views: 7668
Reputation: 60536
You are close:
$this->User->find('all', array('fields' => array('CONCAT(first_name,last_name) AS fullname', 'otherfield'), 'contain' => array());
Upvotes: 7