link() public method
Establishes the relationship between two models.
The relationship is established by setting the foreign key value(s) in one model to be the corresponding primary key value(s) in the other model. The model with the foreign key will be saved into database without performing validation.
If the relationship involves a junction table, a new row will be inserted into the junction table which contains the primary key values from both models.
Note that this method requires that the primary key value is not null.
public void link ( $name, $model, $extraColumns = [] ) | ||
---|---|---|
$name | string |
The case sensitive name of the relationship, e.g. |
$model | yii\db\ActiveRecordInterface |
The model to be linked with the current one. |
$extraColumns | array |
Additional column values to be saved into the junction table. This parameter is only meaningful for a relationship involving a junction table (i.e., a relation set with yii\db\ActiveRelationTrait::via() or yii\db\ActiveQuery::viaTable().) |
throws | yii\base\InvalidCallException |
if the method is unable to link two models. |
Please login to continue.