/** * for when using memcache, if there are subobjects, re-fetch them from cache * to make sure they are up to date * @param Boolean $use_dbw use master DB * @return Model $this */ public function reloadSubs($use_dbw = false) { #elapsed('Model::reloadSubs()'); if (!$this->_refresh_sub_models) { #elapsed('_refresh_sub_models is false'); return $this; } $o = $this; $load = function ($m) use($o, $use_dbw) { if (!Model::isModelClass($m) || !$m->_id) { return; } $m->_force_db = false; $m->getModelAql()->makeProperties(); $m->loadDB($m->_id, $o->_force_db, $use_dbw); $m->construct(); }; $isPlural = function ($type) { return $type === 'plural'; }; foreach ($this->_objects as $o => $type) { #elapsed("$o => $type"); if ($isPlural($type)) { foreach ($this->_data[$o] as $obj) { $load($obj); } } else { $load($this->{$o}); } } return $this; }
/** * Return is dependent on $ext * and is based off of the $value given (ID, IDE, or Model object) * * This is a generic helper method for: * static::convertToID(), static::convertToIDE(), static::convertToObject() * that uses \Model methods of the same name * * @param string $ext * @param string $class * @param mixed $value * @param string $error_code * @return mixed depending on what $ext is * @throws \BadMethodCallException if $class || $ext is invalid * @throws ValidationException if could not get return value */ public static function modelConvertTo($ext, $class, $value, $error_code) { if (!\Model::isModelClass($class)) { $e = sprintf('[%s] is not a valid Model', $class); throw new \BadMethodCallException($e); } $class = '\\' . $class; $exts = array('ID', 'IDE', 'Object'); if (!in_array($ext, $exts)) { $e = sprintf('[convertTo%s] is not a valid method', $ext); throw new \BadMethodCallException($e); } $method = 'convertTo' . $ext; try { return $class::$method($value); } catch (\Exception $e) { self::error($error_code); } }