This code outputs error : Active record "User" is trying to select an invalid column "profile.lastname". Note, the column must exist in the table or be an expression with alias.
Column exists and if I leave $criteria->select = ’ * ’ everythink goes ok and the query is:
SELECT `t`.`id` AS `t0_c0`, `t`.`username` AS `t0_c4`, `t`.`email` AS `t0_c6`, `t`.`date_insert` AS `t0_c9`, `t`.`date_lastvisit` AS `t0_c12`, `t`.`superuser` AS `t0_c16`, `t`.`active` AS `t0_c3`, `profile`.`user_id` AS `t1_c0`, `profile`.`lastname` AS `t1_c1`, `profile`.`firstname` AS `t1_c2`, `profile`.`birthday` AS `t1_c3` FROM `user_users` `t` LEFT OUTER JOIN `user_profiles` `profile` ON (`profile`.`user_id`=`t`.`id`)
but I need just two fields, so way I must select them all.
The same problem is not with this one table, but whit all, if I specify $criteria->select and use with function than I have always an error.
then your sql is still returning all values but in the results you just see specified columns results, all ohters columns are emtpy.
So if you specify $criteria->select than you get about 90 % of all object, so it’s the same as not specify select values.
One more thing, you can specify CONCAT condition in your relational table, even if you describe a new variable in model there is still error in CDbCriteria
$criteria = new CDbCriteria();
$criteria->select = '*';
$criteria->condition = " active = '1' ";
$criteria->with = array('profile' => array('select' => 'user_id, CONCAT(firstname, lastname) AS myvalue'));
and in Profile model add
public $myvalue;
still have error, so there is any way to group similar columns in relational table or it’s an isue.
even if I set alias in condition correct it throws an error:
Active record "Offers" is trying to select an invalid column "userprofile.firstname". Note, the column must exist in the table or be an expression with alias.
It’s strange, when I try to set select condition the query throws this error and when I cut the select condition from criteria everything is ok. I have try with t1 alias but face the same error.
Have other face this problem when using with and trying to select some of needet columns.