diff --git a/include/class.orm.php b/include/class.orm.php index b403617b2e71a0b5211d0274eb0942c1fc2e948a..b4f65e551122d6261e80c26effe8f5ce297d3288 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -73,15 +73,23 @@ class VerySimpleModel { $this->ht[$field] = $value; return; } - // XXX: Ensure $value instanceof $j['fkey'][0] - if ($value->__new__) - $value->save(); - // Capture the object under the object's field name - $this->ht[$field] = $value; + if ($value === null) { + // Pass. Set local field to NULL in logic below + } + elseif ($value instanceof $j['fkey'][0]) { + if ($value->__new__) + $value->save(); + // Capture the object under the object's field name + $this->ht[$field] = $value; + $value = $value->get($j['fkey'][1]); + // Fall through to the standard logic below + } + else + throw new InvalidArgumentException( + 'Expecting NULL or instance of ' . $j['fkey'][0]); + // Capture the foreign key id value $field = $j['local']; - $value = $value->get($j['fkey'][1]); - // Fall through to the standard logic below } // XXX: Fully support or die if updating pk // XXX: The contents of $this->dirty should be the value after the diff --git a/include/class.user.php b/include/class.user.php index f736501fc807c82b75fecf79e4389add1eac9ef2..c169c48cca060cfc019c781e45de1e6620d0f134 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -111,12 +111,7 @@ class UserModel extends VerySimpleModel { function setOrganization($org, $save=true) { - if (is_null($org)) - $this->set('org_id', 0); - elseif ($org instanceof Organization) - $this->set('org', $org); - else // noop - return false; + $this->set('org', $org); if ($save) $this->save();