In CakePHP 1.3 there is a feature for virtual fields but it’s coupled with the database that you are using. For example:
var $virtualFields = array(
'full_name' => 'CONCAT(User.first_name, " ", User.last_name)'
);
This would work for MySQL but not for MS SqlServer. Is there a way to make this database agnostic?
I’m still in the middle of developing an application and still not sure what database we’ll be using in production. That’s why I want to keep all the database access as agnostic as possible.
You could dimension your
Model::virtualFieldsproperty such that it had rules for each database:The trick then is to catch the above property and manipulate it on-the-fly so Cake never realises:
The above code was tested with a simple find on a single model. More testing may be needed to check for edge-cases involving related models. The finished functionality belongs in a behavior. 🙂