Set defaults before saving Objects
This commit is contained in:
parent
f13a7199e1
commit
ef4ecd40fb
|
@ -110,8 +110,9 @@ class ZM_Object {
|
|||
|
||||
public static function _find_one($class, $parameters = array(), $options = array() ) {
|
||||
global $object_cache;
|
||||
if ( ! isset($object_cache[$class]) )
|
||||
if ( ! isset($object_cache[$class]) ) {
|
||||
$object_cache[$class] = array();
|
||||
}
|
||||
$cache = &$object_cache[$class];
|
||||
if (
|
||||
( count($parameters) == 1 ) and
|
||||
|
@ -290,6 +291,16 @@ Logger::Debug("$k => Have default for $v: ");
|
|||
$this->set($new_values);
|
||||
}
|
||||
|
||||
foreach ( $this->defaults as $field => $default ) {
|
||||
if ( (!array_key_exists($field, $this)) or empty($this->{$field}) ) {
|
||||
if ( is_array($default) ) {
|
||||
$this->{$field} = $default['default'];
|
||||
} else {
|
||||
$this->{$field} = $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fields = array_filter(
|
||||
$this->defaults,
|
||||
function($v) {
|
||||
|
|
Loading…
Reference in New Issue