Thursday, May 2, 2013

Model::$virtualFields with associated data

Hello,

I want to build a virtual field from concatinating data from a belongsTo association. 
$virtualFields = array('user_name' => 'CONCAT(User.first_name," ",User.last_name)');

As soon as I add the field I get errors in my application because the resurvice level is set inappropriety.
E.g. for when I add the virtual field to the post model and do:
$this->Comment->recursive = 0; // will load belongsTo Post association, but not the user
$this->Comment->findById($id); // throws SQLSTATE[42S22]: Column not found: 1054 Unknown column 'User.first_name' in 'field list'

Is there any way to either exclude the virtual field for unsufficient recursion levels or for to always load the association?
What is the best practise here?

Thanks
Roland

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: