Select problem

Hi,

I have a CdbException when I try to select columns in second table of join.




 $criteria = new CDbCriteria();

 $criteria->select = array("id","name","surname","society");

 $criteria->with = array("provider");

 $criteria->together = true;

 $_agents = Agent::model()->findAll($criteria); 



‘society’ is column of ‘provider’ table, but Active record not found this column

Thanks

Hi,

in most cases there are no need to explicitly specify columns for select (except queries to tables with many fields or very big fields data from which are not needed), so try to use something like:




 $criteria = new CDbCriteria();

 $criteria->with = array("provider");

 $criteria->together = true;

 $_agents = Agent::model()->findAll($criteria);   


//then you can access society field like:

  foreach ($_agents as $model) {

	echo $model->provider->society;

  }



Also try to (re)read this to better understand how to use active record.

Welcome to community!

Thank you so much for responding so quickly.

I know that without select option it works well but sometimes I’ve big table and I’d like have select option.

I think it’s a bug, because the framework search the column in primary table.

I’ve tested “t1.society”, “provider.society” but it’s the same.

Thanks a lot

It’s definitely not a bug, read this, and you’ll find that solution is like:




...

$criteria->with = array("provider"=>array("select"=>"provider.society"));

...



Try to read documentation more precisely and you’ll find (almost) all answers by yourself.

Thanks so much.

Its’s my bug!!!!

I will study more!

thanks