Yii: Create a personalized relationship between two tables

To make a personalized relationship between two tables in a model, it is possible to add an additional option in the relationship in which one indicates which foreign key should be used with which field.

    public function relations ()
    {
        return array (
            'NameRelation' - array (
                self::HAS_ONE,
                'otherTable,
                '',
                'on''fk_otherTabletable.fk_otherTable ' otherTable.id'
            ),
        );
    }

Leave a Reply