classes/database/orm.php
/**
	 * Returns an ORM model for the given one-one related alias
	 *
	 * @param string $alias name
	 * @return object
	 */
Returns an ORM model for the given one-one related alias
@param string $alias name
@return object
Returns an ORM model for the given one - one related alias @param string $alias name @return object
protected function related($alias)
	{
		if (isset($this->_related[$alias]))
		{
			return $this->_related[$alias];
		}
		elseif (isset(self::$_aliases[$this->name()]['has_one'][$alias]))
		{
			$model = self::$_aliases[$this->name()]['has_one'][$alias]['model'];
			$sql = 'SELECT * FROM "'.$model.'" WHERE "'.$this->name().$this->_foreign_key_suffix.'" = ?';
			if($row = $this->_db->fetch_row($sql, array($this->pk()), 'Model_'. $model))
			{
				return $this->_related[$alias] = $row;
			}
		}
		elseif (isset(self::$_aliases[$this->name()]['belongs_to'][$alias]))
		{
			$this->load();
			$model = self::$_aliases[$this->name()]['belongs_to'][$alias]['model'];
			$sql = 'SELECT * FROM "'.$model.'" WHERE "'.$this->_primary_key.'" = ?';
			$key = $this->_object[$model.$this->_foreign_key_suffix];
			if($row = $this->_db->fetch_row($sql, array($key), 'Model_'. $model))
			{
				return $this->_related[$alias] = $row;
			}
		}
	}
protected function related ( $ alias ) { if ( isset ( $ this -> _related [ $ alias ] ) ) { return $ this -> _related [ $ alias ] ; } elseif ( isset ( self :: $ _aliases [ $ this -> name ( ) ] [ 'has_one' ] [ $ alias ] ) ) { $ model = self :: $ _aliases [ $ this -> name ( ) ] [ 'has_one' ] [ $ alias ] [ 'model' ] ; $ sql = 'SELECT * FROM "' . $ model . '" WHERE "' . $ this -> name ( ) . $ this -> _foreign_key_suffix . '" = ?' ; if ( $ row = $ this -> _db -> fetch_row ( $ sql , array ( $ this -> pk ( ) ) , 'Model_' . $ model ) ) { return $ this -> _related [ $ alias ] = $ row ; } } elseif ( isset ( self :: $ _aliases [ $ this -> name ( ) ] [ 'belongs_to' ] [ $ alias ] ) ) { $ this -> load ( ) ; $ model = self :: $ _aliases [ $ this -> name ( ) ] [ 'belongs_to' ] [ $ alias ] [ 'model' ] ; $ sql = 'SELECT * FROM "' . $ model . '" WHERE "' . $ this -> _primary_key . '" = ?' ; $ key = $ this -> _object [ $ model . $ this -> _foreign_key_suffix ] ; if ( $ row = $ this -> _db -> fetch_row ( $ sql , array ( $ key ) , 'Model_' . $ model ) ) { return $ this -> _related [ $ alias ] = $ row ; } } }
Returns an ORM model for the given one-one related alias
 @param string $alias name
 @return object
Returns an ORM model for the given one - one related alias @param string $alias name @return object
// Get the model name // Build the query // Fetch the results // Get the model name // Build the query // Fetch the results