but not search or sort in columns ‘kat.pavadinimas’ not works. Sort working, when i replace ‘name’=>‘kat.pavadinimas’, to ‘name’ => ‘kat_id’. What is wrong ?
Well, you have to do the searching by yourself inside your model->search() function, so what is the problem to add searching for a related attribute in there?
I add in method model->search() this line: $criteria->compare(‘kat.pavadinimas’,$this->kat->pavadinimas, true); but not working
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('kodas',$this->kodas,true);
$criteria->compare('pavadinimas',$this->pavadinimas,true);
$criteria->compare('intervalas',$this->intervalas,true);
$criteria->compare('kategorijos_id',$this->kategorijos_id);
$criteria->compare('kat.pavadinimas',$this->kat->pavadinimas, true);
return new CActiveDataProvider('Paslauga', array(
'criteria'=>$criteria,
));
}
marque_id have as value: $data->mark_owner->nom_marque
And in my model I use something like that and its works:
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
[color="red"] 'mark_owner'=>array(self::BELONGS_TO,'Marque','marque_id'),[/color]
'line_items'=>array(self::HAS_MANY,'LineItem','article_id')
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'nom' => 'Nom',
'prix' => 'Prix',
'definition' => 'Definition',
'marque_id' => 'Marque',
'image' => 'Image',
);
}
public function behaviors(){
return array( 'EAdvancedArBehavior' => array(
'class' => 'application.extensions.EAdvancedArBehavior'));
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
//var_dump($this);
//exit(0);
//echo 'gggg'.$this->prix;
//exit(0);
/*->find (
array(':nom_marque'=>$this->marque_id));*/
$criteria=new CDbCriteria;
$criteria->with= 'mark_owner';
$criteria->compare('id',$this->id);
$criteria->compare('nom',$this->nom,true);
$criteria->compare('prix',$this->prix);
$criteria->compare('definition',$this->definition,true);
[color="red"]if(!empty($_GET['Article']))
$criteria->compare('mark_owner.nom_marque',Marque::model()->find(array('condition'=>"nom_marque like '%".$_GET['Article']['marque_id']."%'"))->nom_marque, true );[/color]
$criteria->compare('image',$this->image,true);
$criteria->compare('image_zoom',$this->image_zoom,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}