From f2277b61dc290db38f22d1dbf867a869aabafc8d Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 28 Feb 2015 19:53:41 +1100 Subject: [PATCH] More efficient approach to locating a pivot record --- modules/backend/behaviors/RelationController.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index a712f4b0a..acb33e691 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1138,16 +1138,14 @@ class RelationController extends ControllerBehavior * Existing record */ if ($this->manageId) { - $relations = $this->model->{$this->field}; - $config->model = $relations->find($this->manageId); + $config->model = $this->relationModel->find($this->manageId); + $config->data = $this->relationObject->newPivotStatementForId($this->manageId)->first(); - if (!$config->model) { + if (!$config->model || !$config->data) { throw new ApplicationException(Lang::get('backend::lang.model.not_found', [ 'class' => get_class($config->model), 'id' => $this->manageId ])); } - - $config->data = $config->model->pivot; } $widget = $this->makeWidget('Backend\Widgets\Form', $config);