Merge pull request #440 from Flynsarmy/jsonableSettingsModels

Fix jsonable settingsmodel saving
This commit is contained in:
Samuel Georges 2014-07-17 09:55:56 +10:00
commit a7fa3533fd

View File

@ -55,6 +55,7 @@ class SettingsModel extends ModelBehavior
$this->model->bindEvent('model.afterFetch', [$this, 'afterModelFetch']);
$this->model->bindEvent('model.beforeSave', [$this, 'beforeModelSave']);
$this->model->bindEvent('model.setAttribute', [$this, 'setModelAttribute']);
$this->model->bindEvent('model.saveInternal', [$this, 'saveModelInternal']);
/*
* Parse the config
@ -139,15 +140,22 @@ class SettingsModel extends ModelBehavior
$this->model->attributes = array_merge($this->fieldValues, $this->model->attributes);
}
/**
* Internal save method for the model
* @return void
*/
public function saveModelInternal()
{
// Purge the field values from the attributes
$this->model->attributes = array_diff_key($this->model->attributes, $this->fieldValues);
}
/**
* Before the model is saved, ensure the record code is set
* and the jsonable field values
*/
public function beforeModelSave()
{
// Purge the field values from the attributes
$this->model->attributes = array_diff_key($this->model->attributes, $this->fieldValues);
$this->model->item = $this->recordCode;
if ($this->fieldValues)
$this->model->value = $this->fieldValues;
@ -192,4 +200,4 @@ class SettingsModel extends ModelBehavior
{
return $this->fieldConfig;
}
}
}