Skip to content
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

Closed
aadutskevich opened this issue May 22, 2016 · 0 comments
Closed

Setting outputValue after model->save() #124

aadutskevich opened this issue May 22, 2016 · 0 comments

Comments

@aadutskevich
Copy link

aadutskevich commented May 22, 2016

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() in EditableColumnAction. So using callable outputValueyou 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]; }

kartik-v added a commit to kartik-v/yii2-grid that referenced this issue Jul 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants