Active record "Report" is trying to select an invalid column "customers.name".
Note, the column must exist in the table or be an expression with alias.
Yes I tried that, forgot to mention it. I tried even to avoid the MANY_MANY relation and take the associative table into account. Do I have to do use the join option?
Hm that query does look strange if I follow your suggestion. I get no error, but I was not able to retrieve values for the name column in my view
customers_customers can’t be right or?
Querying SQL: SELECT "t"."id" AS "t0_c0", "t"."reportbegin" AS "t0_c2",
"t"."reportend" AS "t0_c3", "customers"."name" AS "t1_c3", "customers"."id" AS
"t1_c0" FROM "shr_report" "t" LEFT OUTER JOIN "shr_report_customer"
"customers_customers" ON ("t"."id"="customers_customers"."report_id") LEFT OUTER
JOIN "shr_customer" "customers" ON ("customers"."id"="customers_customers"."customer_id") LIMIT 10
Validation? I thought this has to be called only when inserting rows?
I still can’t see the values of the Customer.name column.
I added the criteria to the Report->search method. But still no values in the relation column. It’s the same if I want to display the related id column. I am kind of confused. Where else could I have done a mistake?
public function search()
{
$criteria=new CDbCriteria;
$criteria->select ="t.reportbegin,t.reportend";
$criteria->with = array('customers'=>array('select'=>'id'));
$criteria->together = true;
$criteria->compare('id',$this->id);
$criteria->compare('counterreports_id',$this->counterreports_id);
$criteria->compare('reportbegin',$this->reportbegin,true);
$criteria->compare('reportend',$this->reportend,true);
$criteria->compare('importdate',$this->importdate,true);
$criteria->compare('xmlblob',$this->xmlblob,true);
$criteria->compare('status',$this->status);
$criteria->compare('uploaduser',$this->uploaduser,true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
Since the cardinality of the relationship is …-TO-MANY you should normally get an array of related objects. But that may be different when querying via a CDataProvider / accessing via CGridView.
At least you could try this
'value'=>'$data->customers[someindex]->name',
Question is which index to use. It’s possible $row might give you the correct data.
My query log shows that Yii gets all fields from related tables, doesnt’t matter if set for example $criteria->with = array(‘customers’=>array(‘select’=>‘name’)) or not. This might by a performance problem when dealing with many column tables - do you have a same problem?