Hello,
I try to filter and sort in my cgridview through relations. I did it with sucess with most of my models but in one of them I have a complex search function where i can not do it. Here is my search function:
public function search()
{
$alta=AccionesPostventa::model()->FindByAttributes(array(‘accion’=>‘Alta de terminal’))->id;
$baja=AccionesPostventa::model()->FindByAttributes(array(‘accion’=>‘Baja de terminal’))->id;
$cambio=AccionesPostventa::model()->FindByAttributes(array(‘accion’=>‘Cambio de terminal’))->id;
$modificacion=AccionesPostventa::model()->FindByAttributes(array(‘accion’=>‘Modificación de terminal’))->id;
$sql="
SELECT b.id FROM (
SELECT * FROM (SELECT *
FROM postventa
WHERE acciones_postventa_id =:alta
OR acciones_postventa_id =:baja
OR acciones_postventa_id =:cambio
OR acciones_postventa_id =:modificacion
ORDER BY fecha_accion DESC ) a
GROUP BY num_linea_asociada_id
HAVING acciones_postventa_id<>:baja) b";
$criteria=new CDbCriteria;
$criteria->with=array(‘terminales’,‘numerosTelefonos’);
$criteria->addCondition('t.id in ( ‘.$sql.’ ) ');
$criteria->with=array(‘terminales’);
$criteria->compare(‘terminales.imei’,$this->nuevoterminal);
$criteria->compare(‘numerosTelefonos.numero_telefono’,$this->lineaasociada);
$criteria->params=array(’:alta’=>$alta, ‘:baja’=>$baja, ‘:cambio’=>$cambio, ‘:modificacion’=>$modificacion);
$criteria->order=‘fecha_accion asc’;
$acciones=new CActiveDataProvider($this,
array('criteria'=>$criteria,
'sort'=>array(
'attributes'=>array(
'nuevoterminal'=>array(
'asc'=>'terminales.imei',
'desc'=>'terminales.imei DESC',
),
'lineaasociada'=>array(
'asc'=>'numerosTelefonos.numero_telefono',
'desc'=>'numerosTelefonos.numero_telefono DESC',
),
'*',
),
)
));
return $acciones;
}
}
This search functions goes well the first time and my cgridview shows the correct values but when i try to filter with a value, the result query is the same as without filter. I traced the queries and ther is no where condition added for the ->compare in $criteria. The only condition in where is the condition in addCondition.
in my view I have:
array(‘name’=>‘nuevoterminal’,
'value'=> '$data->terminales->imei',
'header'=>'Imei',
'htmlOptions' => array('style' => 'width:130px'),
),
Where nuevoterminal is a public model variable which it is include in rules as safe in search.
Can anyone help me why compares does not appear in queries?
Thanks