public function ref($mode = null) { if (!$this->owner->loaded()) { throw $this->exception('Model must be loaded before traversing reference'); } if ($mode == 'model') { /** @type SQL_Model $m */ $m = $this->add($this->model_name); return $m->addCondition($this->their_field, $this->owner->get($this->our_field)); } $this->restoreConditions(); $this->model->unload(); return $this->model->addCondition($this->their_field, $this->owner->get($this->our_field)); }