mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
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:
parent
02f7149e57
commit
c30b34e4d9
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user