i try to search using this:
$criteria=new CDbCriteria;
$criteria->with=array();
$criteria->compare('cod',$this->cod);
$criteria->compare('nombre',$this->nombre,true);
//search field descripcion from FK references
array_push($criteria->with,'codestado0');
$criteria->addSearchCondition('codestado0.descripcion', $this->codestado);
this code is good when search with nombre or descipcion, but if I search by field cod (PK) optain the next error
CDbException
CDbCommand falló al ejecutar la sentencia SQL: SQLSTATE[42702]: Ambiguous column: 7 ERROR: column reference "cod" is ambiguous
LINE 1: …" ON (“t”.“codmedida”=“codmedida0”.“cod”) WHERE (cod LIKE '…
^. The SQL statement executed was: SELECT COUNT(DISTINCT "t"."cod") FROM "articulo" "t" LEFT OUTER JOIN "estadociclovida" "codestado0" ON ("t"."codestado"="codestado0"."cod") LEFT OUTER JOIN "categoria" "codcategoria0" ON ("t"."codcategoria"="codcategoria0"."cod") LEFT OUTER JOIN "tipomedida" "codmedida0" ON ("t"."codmedida"="codmedida0"."cod") WHERE (cod LIKE :ycp0)
if I remove
array_push($criteria->with,'codestado0');
$criteria->addSearchCondition('codestado0.descripcion', $this->codestado);
and use
search field descripcion from FK references
find is executed normally
Regards…