In special cases, has one/many will require a foreign key set

For example: to pass any constraints imposed by the database
This new logic emulates the "create" method on the relation object
Fixes #1541
This commit is contained in:
Samuel Georges 2015-10-31 16:40:16 +11:00
parent 02f7149e57
commit c30b34e4d9

View File

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