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() ) {
|
public static function _find_one($class, $parameters = array(), $options = array() ) {
|
||||||
global $object_cache;
|
global $object_cache;
|
||||||
if ( ! isset($object_cache[$class]) )
|
if ( ! isset($object_cache[$class]) ) {
|
||||||
$object_cache[$class] = array();
|
$object_cache[$class] = array();
|
||||||
|
}
|
||||||
$cache = &$object_cache[$class];
|
$cache = &$object_cache[$class];
|
||||||
if (
|
if (
|
||||||
( count($parameters) == 1 ) and
|
( count($parameters) == 1 ) and
|
||||||
|
@ -290,6 +291,16 @@ Logger::Debug("$k => Have default for $v: ");
|
||||||
$this->set($new_values);
|
$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(
|
$fields = array_filter(
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
function($v) {
|
function($v) {
|
||||||
|
|
Loading…
Reference in New Issue