-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting outputValue after model->save() #124
Labels
Comments
kartik-v
added a commit
to kartik-v/yii2-grid
that referenced
this issue
Jul 6, 2016
…`EditableColumnAction`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When passing some composite attribute or any attribute that updates relational data via custom setter the model will never new the actual data in
outputValue
callback. It is better to put$value
generation after$model->save()
inEditableColumnAction
. So using callableoutputValue
you can get (re-read from db) actual data of saved model.Before:
if ($model->load($postData)) { $params = [$model, $attribute, $key, $index]; $value = static::parseValue($this->outputValue, $params); if (!$model->save()) { $message = static::parseValue($this->outputMessage, $params); if (empty($message) && $this->showModelErrors) { $message = Html::errorSummary($model, $this->errorOptions); } } else { $message = static::parseValue($this->outputMessage, $params); } return ['output' => $value, 'message' => $message]; }
After:
if ($model->load($postData)) { $params = [$model, $attribute, $key, $index]; if (!$model->save()) { $message = static::parseValue($this->outputMessage, $params); if (empty($message) && $this->showModelErrors) { $message = Html::errorSummary($model, $this->errorOptions); } } else { $message = static::parseValue($this->outputMessage, $params); } $value = static::parseValue($this->outputValue, $params); return ['output' => $value, 'message' => $message]; }
The text was updated successfully, but these errors were encountered: