MacBook avec code sur un bureau

Yii – Create a custom relation between two tables

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'
            ),
        );
    }