protected function _setRelationForeignKeys($relationName)
    {
        /** @var BaseActiveRecord $owner */
        $owner = $this->owner;
        /** @var ActiveQuery $relation */
        $relation = $owner->getRelation($relationName);
        if ($relation->multiple === false && !empty($owner->{$relationName})) {
            Yii::debug("Setting foreign keys for {$relationName}", __METHOD__);
            foreach ($relation->link as $relatedAttribute => $modelAttribute) {
                if ($owner->{$modelAttribute} !== $owner->{$relationName}->{$relatedAttribute}) {
                    if ($owner->{$relationName}->isNewRecord) {
                        $owner->{$relationName}->save();
                    }
                    $owner->{$modelAttribute} = $owner->{$relationName}->{$relatedAttribute};
                }
            }
        }
    }
protected function _setRelationForeignKeys($relationName)
    {
        /** @var BaseActiveRecord $owner */
        $owner = $this->owner;
        /** @var ActiveQuery $relation */
        $relation = $owner->getRelation($relationName);
        if ($relation->multiple === false && !empty($owner->{$relationName})) {
            Yii::debug("Setting foreign keys for {$relationName}", __METHOD__);
            foreach ($relation->link as $relatedAttribute => $modelAttribute) {
                if ($owner->{$modelAttribute} !== $owner->{$relationName}->{$relatedAttribute}) {
                    if ($owner->{$relationName}->isNewRecord) {
                        $owner->{$relationName}->save();
                    }
                    $owner->{$modelAttribute} = $owner->{$relationName}->{$relatedAttribute};
                }
            }
        }
    }
protected function _setRelationForeignKeys ( $ relationName ) { /** @var BaseActiveRecord $owner */ $ owner = $ this -> owner ; /** @var ActiveQuery $relation */ $ relation = $ owner -> getRelation ( $ relationName ) ; if ( $ relation -> multiple === false && ! empty ( $ owner -> { $ relationName } ) ) { Yii :: debug ( "Setting foreign keys for {$relationName}" , __METHOD__ ) ; foreach ( $ relation -> link as $ relatedAttribute => $ modelAttribute ) { if ( $ owner -> { $ modelAttribute } !== $ owner -> { $ relationName } -> { $ relatedAttribute } ) { if ( $ owner -> { $ relationName } -> isNewRecord ) { $ owner -> { $ relationName } -> save ( ) ; } $ owner -> { $ modelAttribute } = $ owner -> { $ relationName } -> { $ relatedAttribute } ; } } } }
Set relation foreign keys that point to owner primary key
@param $relationName
Set relation foreign keys that point to owner primary key