Fradniev
Fradniev

Reputation: 1

Criteria->with error, Id ambiguous

I have a problem with $criteria->with. I'm trying to search in a relation, but it keeps giving me the error: "Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous". I searched for information on the issue and I found that I need an alias.

So, now I have this:

$q=$_POST['q'];
$url=Yii::app()->request->url;
$model=new Peticion('search');
$model->unsetAttributes();


$criteria->compare('t.id',$q,true, 'AND');
//$criteria->compare('decreto.ndecreto',$q,true, 'OR');
//$criteria->compare('decreto.gaceta',$q,true, 'OR');
$criteria->compare('t.tipos_id',$q,true, 'OR');
$criteria->compare('t.vendedor_id',$q,true, 'OR');
$criteria->compare('t.clientes_id',$q,true, 'OR');
$criteria->compare('t.fechacot',$q,true, 'OR');
$criteria->compare('t.metodologia',$q,true, 'OR');
$criteria->compare('t.fechaven',$q,true, 'OR');
$criteria->compare('t.departamento_id',$q,true, 'OR');
$criteria->compare('t.muestras_id',$q,true, 'OR');
$criteria->with = array( 'vendedor');
$criteria->compare('Vendedor.nombre',$q,true, 'OR');

$q is a string which I'm going to use to compare, so i thought it was a relation problem. Here are my relations:

Peticion Model (the table where I'm trying to search)

'vendedor'=>array(self::BELONGS_TO,'Vendedor','vendedor_id'),

Vendedor Model (the relation)

'peticion'=>array(self::HAS_MANY,'Peticion','peticion_id'),

Why am I still getting the error?

Upvotes: 0

Views: 1502

Answers (1)

Sajin
Sajin

Reputation: 151

Please try

$criteria->with = array( 'vendedor' => array('alias'=>'v'));
$criteria->compare('v.nombre',$q,true, 'OR');

Upvotes: 2

Related Questions