diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 9e0f221ed8..899a36b0fd 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1392,14 +1392,15 @@ public function onRelationManagePivotCreate() * Add the checked IDs to the pivot table */ $foreignIds = (array) $this->foreignId; - $this->relationObject->sync($foreignIds, false); + $saveData = $this->pivotWidget->getSaveData(); + $foreignModels = $this->relationModel->whereIn($this->relationModel->getKeyName(), $foreignIds)->get(); + $this->relationObject->syncWithPivotValues($foreignModels, $saveData['pivot'] ?? []); /* * Save data to models */ $foreignKeyName = $this->relationModel->getQualifiedKeyName(); $hydratedModels = $this->relationObject->whereIn($foreignKeyName, $foreignIds)->get(); - $saveData = $this->pivotWidget->getSaveData(); foreach ($hydratedModels as $hydratedModel) { $modelsToSave = $this->prepareModelsToSave($hydratedModel, $saveData);