Fixes pivot model add with showCheckboxes enabled

This commit is contained in:
Samuel Georges 2015-04-29 08:01:28 +10:00
parent 9c166b18be
commit b2e5d24e9d
1 changed files with 14 additions and 4 deletions

View File

@ -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();