public function __get($name) { if ($this->hasAttribute($name)) { return $this->_attributes[$name]; } else { if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) { return $this->_related[$name]; } if ($value = $this->getRelation($name, false)) { $this->_related[$name] = $value->findFor($name, $this); return $this->_related[$name]; } return parent::__get($name); } }