private function _loadOrCreateRelationModel($data, $fks, $modelClass, $relationName)
    {

        /** @var BaseActiveRecord $relationModel */
        $relationModel = null;
        if (!empty($fks)) {
            $relationModel = $modelClass::findOne($fks);
        }
        if (!($relationModel instanceof BaseActiveRecord) && !empty($data)) {
            $relationModel = new $modelClass;
        }
        // If a custom scenario is set, apply it here to correctly be able to set the model attributes
        if (array_key_exists($relationName, $this->_relationsScenario)) {
            $relationModel->setScenario($this->_relationsScenario[$relationName]);
        }
        if (($relationModel instanceof BaseActiveRecord) && is_array($data)) {
            $relationModel->setAttributes($data);
            if ($relationModel->hasMethod('loadRelations')) {
                $relationModel->loadRelations($data);
            }

        }
        return $relationModel;
    }
private function _loadOrCreateRelationModel($data, $fks, $modelClass, $relationName)
    {

        /** @var BaseActiveRecord $relationModel */
        $relationModel = null;
        if (!empty($fks)) {
            $relationModel = $modelClass::findOne($fks);
        }
        if (!($relationModel instanceof BaseActiveRecord) && !empty($data)) {
            $relationModel = new $modelClass;
        }
        // If a custom scenario is set, apply it here to correctly be able to set the model attributes
        if (array_key_exists($relationName, $this->_relationsScenario)) {
            $relationModel->setScenario($this->_relationsScenario[$relationName]);
        }
        if (($relationModel instanceof BaseActiveRecord) && is_array($data)) {
            $relationModel->setAttributes($data);
            if ($relationModel->hasMethod('loadRelations')) {
                $relationModel->loadRelations($data);
            }

        }
        return $relationModel;
    }
private function _loadOrCreateRelationModel ( $ data , $ fks , $ modelClass , $ relationName ) { /** @var BaseActiveRecord $relationModel */ $ relationModel = null ; if ( ! empty ( $ fks ) ) { $ relationModel = $ modelClass :: findOne ( $ fks ) ; } if ( ! ( $ relationModel instanceof BaseActiveRecord ) && ! empty ( $ data ) ) { $ relationModel = new $ modelClass ; } // If a custom scenario is set, apply it here to correctly be able to set the model attributes if ( array_key_exists ( $ relationName , $ this -> _relationsScenario ) ) { $ relationModel -> setScenario ( $ this -> _relationsScenario [ $ relationName ] ) ; } if ( ( $ relationModel instanceof BaseActiveRecord ) && is_array ( $ data ) ) { $ relationModel -> setAttributes ( $ data ) ; if ( $ relationModel -> hasMethod ( 'loadRelations' ) ) { $ relationModel -> loadRelations ( $ data ) ; } } return $ relationModel ; }
Load existing model or create one if no key was provided and data is not empty
@param $data
@param $fks
@param $modelClass
@param $relationName
@return BaseActiveRecord
Load existing model or create one if no key was provided and data is not empty