mauzilla
mauzilla

Reputation: 3592

Return selected fields within a cakePHP model find

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

Answers (1)

Andreas Wong
Andreas Wong

Reputation: 60536

You are close:

$this->User->find('all', array('fields' => array('CONCAT(first_name,last_name) AS fullname', 'otherfield'), 'contain' => array());

Upvotes: 7

Related Questions