From 5a843bc90986a29ec0375697490af9864ecbd188 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sun, 23 Aug 2020 23:57:05 -0600 Subject: [PATCH] Fix support for updating belongsTo relationships with the RelationController. Fixes #5198, #5243; replaces #5217. Related: https://github.com/octobercms/october/commit/6e25c5a8d0834aa083455f9f2b7c75b9bda7ff1c# --- modules/backend/behaviors/RelationController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index f6c96382d..c8becee6b 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1157,7 +1157,11 @@ class RelationController extends ControllerBehavior } } elseif ($this->viewMode == 'single') { - $this->viewModel = $this->manageWidget->model; + // Ensure that the view widget model is the same instance as the manage widget model + // since they will technically be different object instances in this context as + // $viewWidet->model is populated by $this->relationModel->getResults() and + // $manageWidget->model is populated by $this->relationModel->find($manageId); + $this->viewModel = $this->viewWidget->model = $this->manageWidget->model; $this->viewWidget->setFormValues($saveData); $this->viewModel->save(null, $this->manageWidget->getSessionKey());