Set defaults before saving Objects

This commit is contained in:
Isaac Connor 2020-01-10 12:44:59 -05:00
parent f13a7199e1
commit ef4ecd40fb
1 changed files with 12 additions and 1 deletions

View File

@ -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) {