public function validateRelation($attribute, $params)
    {
        $relation = $this->getRelation($attribute);
        $attributes = isset($params['attributes']) ? $params['attributes'] : null;
        $errors = [];

        $models = $this->$attribute;
        if (!$relation->multiple) {
            $models = [$models];
        }
        /** @var \yii\db\ActiveRecord[] $models */
        foreach ($models as $index => $model) {
            if (isset($params['scenario'])) {
                $model->scenario = $params['scenario'];
            }

            if ($model->validate($attributes)) {
                continue;
            }
            $errors[] = (string)$model . ': ' . \yii\helpers\Html::errorSummary($model, ['header' => '']) ;
        }

        $this->populateRelation($attribute, $relation->multiple ? $models : $models[0]);
        if (empty($errors)) {
            return;
        }

        $errors = "<ul><li>" . implode("</li>\n<li>", $errors) . "</li></ul>";

        $placeholders = [
            'attribute' => $this->getRelationLabel($relation, $attribute),
        ];
        $message = $relation->multiple
            ? \Yii::t('app', '{attribute} have invalid items:', $placeholders)
            : \Yii::t('app', '{attribute} is invalid:', $placeholders);
        $this->addError($attribute, $message . $errors);
    }
public function validateRelation($attribute, $params)
    {
        $relation = $this->getRelation($attribute);
        $attributes = isset($params['attributes']) ? $params['attributes'] : null;
        $errors = [];

        $models = $this->$attribute;
        if (!$relation->multiple) {
            $models = [$models];
        }
        /** @var \yii\db\ActiveRecord[] $models */
        foreach ($models as $index => $model) {
            if (isset($params['scenario'])) {
                $model->scenario = $params['scenario'];
            }

            if ($model->validate($attributes)) {
                continue;
            }
            $errors[] = (string)$model . ': ' . \yii\helpers\Html::errorSummary($model, ['header' => '']) ;
        }

        $this->populateRelation($attribute, $relation->multiple ? $models : $models[0]);
        if (empty($errors)) {
            return;
        }

        $errors = "<ul><li>" . implode("</li>\n<li>", $errors) . "</li></ul>";

        $placeholders = [
            'attribute' => $this->getRelationLabel($relation, $attribute),
        ];
        $message = $relation->multiple
            ? \Yii::t('app', '{attribute} have invalid items:', $placeholders)
            : \Yii::t('app', '{attribute} is invalid:', $placeholders);
        $this->addError($attribute, $message . $errors);
    }
public function validateRelation ( $ attribute , $ params ) { $ relation = $ this -> getRelation ( $ attribute ) ; $ attributes = isset ( $ params [ 'attributes' ] ) ? $ params [ 'attributes' ] : null ; $ errors = [ ] ; $ models = $ this -> $ attribute ; if ( ! $ relation -> multiple ) { $ models = [ $ models ] ; } /** @var \yii\db\ActiveRecord[] $models */ foreach ( $ models as $ index => $ model ) { if ( isset ( $ params [ 'scenario' ] ) ) { $ model -> scenario = $ params [ 'scenario' ] ; } if ( $ model -> validate ( $ attributes ) ) { continue ; } $ errors [ ] = ( string ) $ model . ': ' . \ yii \ helpers \ Html :: errorSummary ( $ model , [ 'header' => '' ] ) ; } $ this -> populateRelation ( $ attribute , $ relation -> multiple ? $ models : $ models [ 0 ] ) ; if ( empty ( $ errors ) ) { return ; } $ errors = "<ul><li>" . implode ( "</li>\n<li>" , $ errors ) . "</li></ul>" ; $ placeholders = [ 'attribute' => $ this -> getRelationLabel ( $ relation , $ attribute ) , ] ; $ message = $ relation -> multiple ? \ Yii :: t ( 'app' , '{attribute} have invalid items:' , $ placeholders ) : \ Yii :: t ( 'app' , '{attribute} is invalid:' , $ placeholders ) ; $ this -> addError ( $ attribute , $ message . $ errors ) ; }
Validates related models.
@param string $attribute the attribute currently being validated
@param mixed $params the value of the "params" given in the rule
Validates related models .