But now, I want to filter by brand and I tried to do the same but there are not related directly, I can’t do $criteria->with = array(‘brand’). Project table doesn’t know the brand table. I think I have to work with the realisation table to get the brand table but I don’t know how to do this!
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
if($this->rea_name)
{
$criteria->together = true;
$criteria->with = array('realisation');
$criteria->compare('realisation.name',$this->rea_name,true);
}
if($this->brand_name)
{
$criteria->together = true;
$criteria->with = array('realisation.brand');
$criteria->compare('brand.name', $this->brand_name,true);
}
$sort=new CSort;
$sort->attributes=array(
'id',
'rea_name' => array(
'asc' => 'realisation.name',
'desc' => 'realisation.name DESC',
'label' => 'Réalisation',
),
'brand_name' => array(
'asc' => 'brand.name',
'desc' => 'brand.name DESC',
'label' => 'Marque',
),
'*');
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort' => $sort,
));
}
It works with both realisation name and brand name together but when I try with the name of a project with one of them, I have the ambigus clause name.