CakePHP: virtual fields containing model related data fields

1Seeker

New Member
I've got a model Employee which belongsTo an Address-model. When I fetch data from the Employees model, the associated Address record gets fetched too. Additionally, the Address model has a virtualField full_name. This looks like this:\[code\]Array ([0] => Array ( [Employee] => Array ( [id] => 1 [address_id] => 33 [username] => ... ... ) [Address] => Array ( [id] => 33 [firstname] => Blah [full_name] => Blah Blubb ... ) )[1] => Array ( [Employee] => Array ( [id] => 2 ...\[/code\]I want to have included this virtualField in the Employee part of the data array too, like\[code\]Array ([0] => Array ( [Employee] => Array ( [id] => 1 [full_name] => Blah Blubb ... )\[/code\]Tis isn't possible to solve by just adding\[code\]$virtualFields = array( 'full_name' => 'CONCAT_WS(" ", Address.firstname, Address.surname)',);\[/code\]to the Employees model, as the Cookbook states There is a solution proposed ("copy virtualFields from one model to another at runtime when you need to access them"), but I don't understand this solution. Where do I have to place this? In the controller? In the model in the find function?Thanks for Help
 
Back
Top