src/Database/Model/Relatable.php
public function belongsTo($model, $options = array())
    {
        if (isset($this->_relationsCache[$model])) {
            return $this->_relationsCache[$model];
        }

        $options = static::getRelationInfo($model, $options);

        if (!isset($options['localKey'])) {
            $options['localKey'] = Inflector::foreignKey($model);
        }

        if (!isset($options['foreignKey'])) {
            $options['foreignKey'] = $options['model']::primaryKey();
        }

        return $this->_relationsCache[$model] = $options['model']::select()
            ->where("{$options['foreignKey']} = ?", $this->{$options['localKey']})
            ->fetch();
    }
public function belongsTo($model, $options = array())
    {
        if (isset($this->_relationsCache[$model])) {
            return $this->_relationsCache[$model];
        }

        $options = static::getRelationInfo($model, $options);

        if (!isset($options['localKey'])) {
            $options['localKey'] = Inflector::foreignKey($model);
        }

        if (!isset($options['foreignKey'])) {
            $options['foreignKey'] = $options['model']::primaryKey();
        }

        return $this->_relationsCache[$model] = $options['model']::select()
            ->where("{$options['foreignKey']} = ?", $this->{$options['localKey']})
            ->fetch();
    }
public function belongsTo ( $ model , $ options = array ( ) ) { if ( isset ( $ this -> _relationsCache [ $ model ] ) ) { return $ this -> _relationsCache [ $ model ] ; } $ options = static :: getRelationInfo ( $ model , $ options ) ; if ( ! isset ( $ options [ 'localKey' ] ) ) { $ options [ 'localKey' ] = Inflector :: foreignKey ( $ model ) ; } if ( ! isset ( $ options [ 'foreignKey' ] ) ) { $ options [ 'foreignKey' ] = $ options [ 'model' ] :: primaryKey ( ) ; } return $ this -> _relationsCache [ $ model ] = $ options [ 'model' ] :: select ( ) -> where ( "{$options['foreignKey']} = ?" , $ this -> { $ options [ 'localKey' ] } ) -> fetch ( ) ; }
Returns the owning object.

@param string $model   Name of the model.
@param aray   $options Optional relation options.

@return object
Returns the owning object .