Yii – Create a custom relation between two tables

MacBook avec code sur un bureau

To make a custom relationship between two tables in a model, it is possible to add an additional option in the relation in which one indicates which foreign key should be used with which field. public function relations() { return array( ‘nomRelation’ => array( self::HAS_ONE, ‘otherTable, ”, ‘on’=>’thisTable.fk_otherTable = otherTable.id’ ), ); }

Categories yii