From 71241ee6d4d308a37873c123a49cf903ca011ed7 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Wed, 12 Jun 2019 00:26:55 -0600 Subject: [PATCH] Fix error messages in RelationController Fixes #4342 --- .../backend/behaviors/RelationController.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index fa44ecbfe..74a83ebb5 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -320,17 +320,16 @@ class RelationController extends ControllerBehavior } if (!$this->model) { - throw new ApplicationException(Lang::get( - 'backend::lang.relation.missing_model', - ['class'=>get_class($this->controller)] - )); + throw new ApplicationException(Lang::get('backend::lang.relation.missing_model', [ + 'class' => get_class($this->controller), + ])); } if (!$this->model instanceof Model) { - throw new ApplicationException(Lang::get( - 'backend::lang.model.invalid_class', - ['model'=>get_class($this->model), 'class'=>get_class($this->controller)] - )); + throw new ApplicationException(Lang::get('backend::lang.model.invalid_class', [ + 'model' => get_class($this->model), + 'class' => get_class($this->controller), + ])); } if (!$this->getConfig($field)) { @@ -901,10 +900,13 @@ class RelationController extends ControllerBehavior * Existing record */ if ($this->manageId) { - $config->model = $config->model->find($this->manageId); - if (!$config->model) { + $model = $config->model->find($id); + if ($model) { + $config->model = $model; + } else { throw new ApplicationException(Lang::get('backend::lang.model.not_found', [ - 'class' => get_class($config->model), 'id' => $this->manageId + 'class' => get_class($config->model), + 'id' => $this->manageId, ])); } } @@ -950,10 +952,12 @@ class RelationController extends ControllerBehavior if ($this->manageId) { $hydratedModel = $this->relationObject->where($foreignKeyName, $this->manageId)->first(); - $config->model = $hydratedModel; - if (!$config->model) { + if ($hydratedModel) { + $config->model = $hydratedModel; + } else { throw new ApplicationException(Lang::get('backend::lang.model.not_found', [ - 'class' => get_class($config->model), 'id' => $this->manageId + 'class' => get_class($config->model), + 'id' => $this->manageId, ])); } }