diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index cf302780b32de046ebbcc5a103ac66d399194e8a..c5b021c12c5437c44deb0a86ff9fe4d1cce9543e 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -748,7 +748,7 @@ class DynamicFormEntryAnswer extends VerySimpleModel { } function getValue() { - if (!$this->_value) + if (!$this->_value && isset($this->value)) $this->_value = $this->getField()->to_php( $this->get('value'), $this->get('value_id')); return $this->_value; diff --git a/include/class.orm.php b/include/class.orm.php index 4a6102de98027654ee6bcca7286f5df7b72952ef..0e8b3065429ef53e1a1bceb9d82dc99f6bf60ac4 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -36,10 +36,7 @@ class VerySimpleModel { $this->dirty = array(); } - function get($field) { - return $this->ht[$field]; - } - function __get($field) { + function get($field, $default=false) { if (array_key_exists($field, $this->ht)) return $this->ht[$field]; elseif (isset(static::$meta['joins'][$field])) { @@ -50,9 +47,14 @@ class VerySimpleModel { array($j['fkey'][1] => $this->ht[$j['local']])); return $v; } + if (isset($default)) + return $default; throw new OrmException(sprintf('%s: %s: Field not defined', get_class($this), $field)); } + function __get($field) { + return $this->get($field, null); + } function __isset($field) { return array_key_exists($field, $this->ht) @@ -78,7 +80,7 @@ class VerySimpleModel { $this->ht[$field] = $value; // Capture the foreign key id value $field = $j['local']; - $value = $value->{$j['fkey'][1]}; + $value = $value->get($j['fkey'][1]); // Fall through to the standard logic below } // XXX: Fully support or die if updating pk