From b2e5d24e9d389f4bc601848c1cf9c47ef3fc20ae Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 29 Apr 2015 08:01:28 +1000 Subject: [PATCH] Fixes pivot model add with showCheckboxes enabled --- .../backend/behaviors/RelationController.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 0e7049578..95d007540 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -746,11 +746,12 @@ class RelationController extends ControllerBehavior $config->context = $this->evalFormContext('pivot', !!$this->manageId); $config->alias = $this->alias . 'ManagePivotForm'; + $foreignKeyName = $this->relationModel->getQualifiedKeyName(); + /* * Existing record */ if ($this->manageId) { - $foreignKeyName = $this->relationModel->getQualifiedKeyName(); $hydratedModel = $this->relationObject->where($foreignKeyName, $this->manageId)->first(); $config->model = $hydratedModel; @@ -760,10 +761,19 @@ class RelationController extends ControllerBehavior ])); } } + /* + * New record + */ else { - if ($this->foreignId && ($foreignModel = $this->relationModel->find($this->foreignId))) { - $foreignModel->exists = false; - $config->model = $foreignModel; + if ($this->foreignId) { + $foreignModel = $this->relationModel + ->whereIn($foreignKeyName, (array) $this->foreignId) + ->first(); + + if ($foreignModel) { + $foreignModel->exists = false; + $config->model = $foreignModel; + } } $pivotModel = $this->relationObject->newPivot();