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_addresst LEFT OUTER JOIN nerp_bp_generalMBPAddress_bp_code_BT ON (t.bp_code=MBPAddress_bp_code_BT.id) WHERE (id=:value)
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;
}
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();
}