0
public function __get($name) {
0
- if (isset($this->$name))
0
- $model_name = get_class($this);
0
- $placeholders = (isset($this->__placeholders) and $this->__placeholders);
0
- Trigger::current()->filter($filtered, $model_name."_".$name."_attr", $this);
0
- if ($filtered !== false)
0
- $this->$name = $filtered;
0
- $this->belongs_to = (array) $this->belongs_to;
0
- $this->has_many = (array) $this->has_many;
0
- $this->has_one = (array) $this->has_one;
0
- if (in_array($name, $this->belongs_to) or isset($this->belongs_to[$name])) {
0
- $class = (isset($this->belongs_to[$name])) ? $this->belongs_to[$name] : $name ;
0
- return $this->$name = new $class($this->{$name."_id"});
0
- } elseif (in_array($name, $this->has_many) or isset($this->has_many[$name])) {
0
- if (isset($this->has_many[$name]))
0
- list($class, $by) = $this->has_many[$name];
0
- list($class, $by) = array(depluralize($name), $model_name);
0
- return $this->$name = call_user_func(array($class, "find"),
0
- array("where" => array(strtolower($by)."_id" => $this->id),
0
- "placeholders" => $placeholders));
0
- } elseif (in_array($name, $this->has_one)) {
0
- $class = depluralize($name);
0
- return $this->$name = new $class(null, array("where" => array(strtolower($model_name)."_id" => $this->id)));
0
+ $model_name = get_class($this);
0
+ $placeholders = (isset($this->__placeholders) and $this->__placeholders);
0
+ Trigger::current()->filter($filtered, $model_name."_".$name."_attr", $this);
0
+ if ($filtered !== false)
0
+ $this->$name = $filtered;
0
+ $this->belongs_to = (array) $this->belongs_to;
0
+ $this->has_many = (array) $this->has_many;
0
+ $this->has_one = (array) $this->has_one;
0
+ if (in_array($name, $this->belongs_to) or isset($this->belongs_to[$name])) {
0
+ $class = (isset($this->belongs_to[$name])) ? $this->belongs_to[$name] : $name ;
0
+ if (isset($this->belongs_to[$name])) {
0
+ $opts =& $this->belongs_to[$name];
0
+ $model = oneof(@$opts["model"], $name);
0
+ $match = oneof(@$opts["by"], strtolower($name));
0
+ $where = array_merge(array("id" => $this->{$match."_id"}),
0
+ (array) @$opts["where"]);
0
+ $where = array("id" => $this->{$name."_id"});
0
+ return $this->$name = new $model(null, array("where" => $where));
0
+ } elseif (in_array($name, $this->has_many) or isset($this->has_many[$name])) {
0
+ if (isset($this->has_many[$name])) {
0
+ $opts =& $this->has_many[$name];
0
+ $model = oneof($opts["model"], $name);
0
+ $match = oneof(@$opts["by"], strtolower($name));
0
+ $where = array_merge(array($match."_id" => $this->id),
0
+ (array) @$opts["where"]);
0
+ $model = depluralize($name);
0
+ $where = array(strtolower($match)."_id" => $this->id);
0
+ return $this->$name = call_user_func(array($model, "find"),
0
+ array("where" => $where,
0
+ "placeholders" => $placeholders));
0
+ } elseif (in_array($name, $this->has_one)) {
0
+ $class = depluralize($name);
0
+ return $this->$name = new $class(null, array("where" => array(strtolower($model_name)."_id" => $this->id)));
0
if ($model_name == "visitor")
0
+ if (!isset($id) and isset($options["where"]["id"]))
0
+ $id = $options["where"]["id"];
0
$cache = (is_numeric($id) and isset(self::$caches[$model_name][$id])) ?
0
self::$caches[$model_name][$id] :
0
((isset($options["read_from"]["id"]) and isset(self::$caches[$model_name][$options["read_from"]["id"]])) ?