Hello,
I’ve a table with three fields which having reference on another table. I want to create a relation on all three fields.
Table A:
/**
* Model class A for table A
*
* @property integer $id
* and other fields too
*/
class A extends CActiveRecord {
...
public function relations() {
return array(
'b' => array(self::HAS_MANY, 'B', 'id_1_of_b')
);
}
...
}
Table B:
/**
* Model class B for table B
*
* @property integer $id
* @property integer $id_1_of_b
* @property integer $id_2_of_b
* @property integer $id_3_of_b
* and other fields too
*/
class B extends CActiveRecord {
...
public function relations() {
return array(
'a' => array(self::BELONGS_TO, 'A', 'id_1_of_b')
);
}
...
}
Above I’ve mentioned just one field, but want to link all three fields for JOIN condition like:
SELECT * FROM `B` `b`
LEFT OUTER JOIN `A` `a` ON (`a`.`id_1_of_b` = `b`.`id` OR `a`.`id_2_of_b` = `b`.`id` OR `a`.`id_3_of_b` = `b`.`id`)
How can I do this in model class relations?