Refresh Relation Manager on Unlink and Delete (#4741)

Credit to @DanHarrin. Fixes #3470 and #4718. Replaces #3476.
This commit is contained in:
Dan Harrin 2019-12-17 15:16:55 +00:00 committed by Ben Thomson
parent a53cc52752
commit 3fc7f6aa76
1 changed files with 9 additions and 0 deletions

View File

@ -1187,6 +1187,9 @@ class RelationController extends ControllerBehavior
$relatedModel->delete();
}
// Reinitialise the form with a blank model
$this->initRelation($this->model);
$this->viewWidget->setFormValues([]);
$this->viewModel = $this->relationModel;
}
@ -1281,6 +1284,12 @@ class RelationController extends ControllerBehavior
if ($this->relationType == 'belongsTo') {
$this->relationObject->dissociate();
$this->relationObject->getParent()->save();
// If the relation manager isn't using deferred binding, reinitialise the form with a blank model
if (is_null($sessionKey)) {
$this->model->refresh();
$this->initRelation($this->model);
}
}
elseif ($this->relationType == 'hasOne' || $this->relationType == 'morphOne') {
if ($obj = $relatedModel->find($recordId)) {