diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index a2813d876..de09b21fe 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -913,6 +913,19 @@ class RelationController extends ControllerBehavior if ($this->viewMode == 'multi') { $newModel = $this->relationModel; + + /* + * In special cases, has one/many will require a foreign key set + * to pass any constraints imposed by the database. This emulates + * the "create" method on the relation object. + */ + if (in_array($this->relationType, ['hasOne', 'hasMany'])) { + $newModel->setAttribute( + $this->relationObject->getPlainForeignKey(), + $this->relationObject->getParentKey() + ); + } + $modelsToSave = $this->prepareModelsToSave($newModel, $saveData); foreach ($modelsToSave as $modelToSave) { $modelToSave->save(null, $this->manageWidget->getSessionKey());