From 3fc7f6aa7672acb381a712e83b6a2f68f28ccfca Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Tue, 17 Dec 2019 15:16:55 +0000 Subject: [PATCH] Refresh Relation Manager on Unlink and Delete (#4741) Credit to @DanHarrin. Fixes #3470 and #4718. Replaces #3476. --- modules/backend/behaviors/RelationController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index deb84260f..4f72e224d 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -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)) {