Error Alias When Setdbcriteria() With Relation

I changes dbCriteria in Model. I was not able to create new record. I know that the issues related to aliases but not overcome.


public function beforeFind()

{

  $this->getDbCriteria()->mergeWith(array(

    'with'=>"MBPAddress_bp_code_BT",

    'condition'=>"MBPAddress_bp_code_BT.type=3",

 ));

 parent::beforeFind();

}

I was not able to create new record. I know that the issues related to aliases but not overcome.

ERROR:

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘id’ in where clause is ambiguous. The SQL statement executed was: SELECT t.id AS t0_c0, t.bp_code AS

t1_c57 FROM nerp_bp_address t LEFT OUTER JOIN nerp_bp_general MBPAddress_bp_code_BT ON (t.bp_code=MBPAddress_bp_code_BT.id) WHERE (id=:value)

The parameters that you’re passing to the find method are the problem here. You probably just need to change the ‘id’ key to ‘t.id’.

I identified the problem in the validate function in CModel, do not know how to solve.


public function validate($attributes=null, $clearErrors=true)

{

	if($clearErrors)

		$this->clearErrors();

	if($this->beforeValidate())

	{

		foreach($this->getValidators() as $validator)

			$validator->validate($this,$attributes); //This line is the line causing the error.

		$this->afterValidate();

		return !$this->hasErrors();

	}

	else

		return false;

}

Which of your validation rules is triggering it?

I want to use this code in the Model. Can you help me to bug off.


public function beforeFind()

{

  $this->getDbCriteria()->mergeWith(array(

    'with'=>"MBPAddress_bp_code_BT",

    'condition'=>"MBPAddress_bp_code_BT.type=3",

 ));

 parent::beforeFind();

}

My code hampered by validateAttribute($object,$attribute) in CUniqueValidator class.

In $criteria, condition hasn’t alias prefix.

I think CExistValidator same.