From afc31fcbb4cc64923ba839ea04cf611b51775df4 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 22 Apr 2014 12:42:27 -0500 Subject: [PATCH] orm: Make __get() and get() consistent --- include/class.dynamic_forms.php | 2 +- include/class.orm.php | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index cf302780b..c5b021c12 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 4a6102de9..0e8b30654 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 -- GitLab