I create a CDbCriteria object that is going to be used to find records through AR.
In the select property of the criteria object, I have database functions, like SUBSTR or CONCAT. The problem is when I try to get the related records with the with property. If I don’t get the child records, the query runs ok, but if I uncomment the with property, I get an exception.
If I comment the with and order properties (because the latter depends on the former), the query runs fine.
The exception I get is:
2012/10/24 22:55:57 [error] [exception.CDbException] exception 'CDbException' with message 'Active record "CustomerLocations" is trying to select an invalid column "' '". Note, the column must exist in the table or be an expression with alias.' in .../source/yii/framework/db/ar/CActiveFinder.php:940
#0 /.../source/yii/framework/db/ar/CActiveFinder.php(1232): CJoinElement->getColumnSelect('t.name, CONCAT(...')
If you mean to try and run the query in mysql client, yes, I already did (I usually first run the queries there and then write them in PHP) and it had no issues.
Anyway, this is a rather simple case. Instead of concatenating the fields in MySQL, I do this in PHP, so no harm done. However, there could be cases that I couldn’t circumvent this issue in PHP, because I could use MySQL functions that do not exist in PHP.
Ok, thanks for the tip. But this is an event that runs every each find, which is not always the case for me (plus the small overhead in each find()). And it’s inside the PHP code. As I said, what about other MySQL functions that I would like to run that couldn’t be “emulated” in PHP?