0

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?

Owen S.
  • 7,665
  • 1
  • 28
  • 44
Fradniev
  • 1
  • 3

1 Answers1

2

Please try

$criteria->with = array( 'vendedor' => array('alias'=>'v'));
$criteria->compare('v.nombre',$q,true, 'OR');
xlembouras
  • 8,215
  • 4
  • 33
  • 42
Sajin
  • 141
  • 2
  • @xlembouras i just try that, but still i got the error: `Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous. The SQL statement executed was: SELECT COUNT(DISTINCT 't'.'id') FROM 'peticion' 't' LEFT OUTER JOIN 'vendedor' 'v' ON ('t'.'vendedor_id'='v'.'id')` – Fradniev Jun 02 '14 at 11:43