CakePHP - Column Aliases in SQL Queries

Is there a good way to specify column aliases when performing find () operations on a model?

$this->User->find('first', array( 'fields' => array( 'CONCAT(firstname, ' ', surname) AS fullname', 'email', 'tel' ) ); 

At the moment, if I do it like this, it returns data as follows:

 Array ( [0] => Array ( [fullname] => John Smith ) [User] => Array ( [email] => jsmith@example.com [tel] => 0123456789 ) ) 

Is there a way to return column aliases to it, such as regular columns?

 Array ( [User] => Array ( [fullname] => John Smith [email] => jsmith@example.com [tel] => 0123456789 ) ) 
+4
source share
2 answers

For this you must use Virtual Fields .

+8
source

For cakephp 2.x in the request:

 'CONCAT(firstname, ' ', surname) AS User__fullname', 

http://book.cakephp.org/2.0/en/models/virtual-fields.html#virtual-fields-in-sql-queries

0
source

All Articles