/** * * Fetches the related record or collection for a native ID or record. * * @param mixed $spec If a scalar, treated as the native primary key * value; if an array or record, retrieves the native primary key value * from it. * * @return object The related record or collection object. * */ public function fetch($spec) { if ($spec instanceof Solar_Sql_Model_Record || is_array($spec)) { $native_id = $spec[$this->native_col]; } else { $native_id = $spec; } $where = array(); $cond = "{$this->foreign_alias}.{$this->foreign_col} = ?"; $where[$cond] = $native_id; $where = array_merge($where, $this->getForeignConditions($this->foreign_alias)); $fetch = array('alias' => $this->foreign_alias, 'where' => $where, 'order' => $this->order); if ($this->isOne()) { $obj = $this->_foreign_model->fetchOne($fetch); } elseif ($this->isMany()) { $obj = $this->_foreign_model->fetchAll($fetch); } else { throw $this->_exception('ERR_NOT_ONE_OR_ALL', array('class' => get_class($this))); } if (!$obj) { $obj = $this->fetchEmpty(); } return $obj; }