Fixes #1042 - remove fillable constraint on models when saving

Form fields are already constrained by their fields.yaml definition (values not defined in the yaml will not be saved) so we don't need to double dip by enforcing fillable too.
This commit is contained in:
Samuel Georges 2015-10-17 11:40:07 +11:00
parent f12101671e
commit af657e9399
2 changed files with 10 additions and 10 deletions

View File

@ -912,15 +912,13 @@ class RelationController extends ControllerBehavior
$sessionKey = $this->deferredBinding ? $this->relationGetSessionKey(true) : null;
if ($this->viewMode == 'multi') {
if ($this->relationType == 'hasMany') {
$newModel = $this->relationObject->create($saveData, $sessionKey);
}
elseif ($this->relationType == 'belongsToMany') {
$newModel = $this->relationObject->create($saveData, [], $sessionKey);
$newModel = $this->relationModel;
$modelsToSave = $this->prepareModelsToSave($newModel, $saveData);
foreach ($modelsToSave as $modelToSave) {
$modelToSave->save(null, $this->manageWidget->getSessionKey());
}
$newModel->commitDeferred($this->manageWidget->getSessionKey());
$this->relationObject->add($newModel, $sessionKey);
}
elseif ($this->viewMode == 'single') {
$newModel = $this->viewModel;
@ -961,8 +959,10 @@ class RelationController extends ControllerBehavior
if ($this->viewMode == 'multi') {
$model = $this->relationModel->find($this->manageId);
$model->fill($saveData);
$model->save(null, $this->manageWidget->getSessionKey());
$modelsToSave = $this->prepareModelsToSave($model, $saveData);
foreach ($modelsToSave as $modelToSave) {
$modelToSave->save(null, $this->manageWidget->getSessionKey());
}
}
elseif ($this->viewMode == 'single') {
$this->viewWidget->setFormValues($saveData);

View File

@ -291,7 +291,7 @@ class Form extends WidgetBase
$data = $this->getSaveData();
}
$this->model->fill($data);
$this->model->forceFill($data);
$this->data = (object) array_merge((array) $this->data, (array) $data);
foreach ($this->allFields as $field) {