You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public function afterValidate()
{
/** @var ActiveRecord[] $translations */
$translations = $this->owner->{$this->translationRelation};
$attributeNames = null;
if (!empty($translations)) { // get 1st, all models are same
$attributeNames = array_keys($translations[0]->getAttributes());
$attributeNames = array_combine($attributeNames, $attributeNames); // key = value
if ($this->owner->getIsNewRecord()) {
foreach ($this->owner->getRelation($this->translationRelation)->link as $a => $b) {
//skip FK checks, our record will be saved later and we trust Yii2 it will have correct ID
unset($attributeNames[$a]);
}
}
}
if (!Model::validateMultiple($translations, $attributeNames)) {
$errors = [];
foreach ($translations as $model) {
if ($model->hasErrors()){
$errors = $model->getErrors();
}
}
$this->owner->addError($this->translationRelation, $errors);
}
}
А то если валидация не проходит возвращается пустая ошибка от релейшена! а так будут ошибки модели возвращаться.
The text was updated successfully, but these errors were encountered: