protected function loadBelongsTo(
        Collection $relations,
        BelongsTo $relationClass,
        Model $relationModel,
        Model $model,
        Builder $query,
        $direction
    ) {
        $foreignKey = $relationClass->getOwnerKey();
        $ownerKey = $relationClass->getForeignKey();

        $ownerTable = $model->getTable();
        $foreignTable = $relationModel->getTable();

        $ownerColumn = implode('.', [$ownerTable, $ownerKey]);
        $foreignColumn = implode('.', [$foreignTable, $foreignKey]);
        $sortedColumnRaw = '`'.$foreignTable.'`.`'.$relations->last().'`';
        $sortedColumnAlias = implode('__', [$foreignTable, $relations->last()]);

        $this->sortedColumnAlias = $sortedColumnAlias;

        $query
            ->addSelect([DB::raw($sortedColumnRaw.' AS '.$sortedColumnAlias)])
            ->join($foreignTable, $foreignColumn, '=', $ownerColumn, 'left');
    }
protected function loadBelongsTo(
        Collection $relations,
        BelongsTo $relationClass,
        Model $relationModel,
        Model $model,
        Builder $query,
        $direction
    ) {
        $foreignKey = $relationClass->getOwnerKey();
        $ownerKey = $relationClass->getForeignKey();

        $ownerTable = $model->getTable();
        $foreignTable = $relationModel->getTable();

        $ownerColumn = implode('.', [$ownerTable, $ownerKey]);
        $foreignColumn = implode('.', [$foreignTable, $foreignKey]);
        $sortedColumnRaw = '`'.$foreignTable.'`.`'.$relations->last().'`';
        $sortedColumnAlias = implode('__', [$foreignTable, $relations->last()]);

        $this->sortedColumnAlias = $sortedColumnAlias;

        $query
            ->addSelect([DB::raw($sortedColumnRaw.' AS '.$sortedColumnAlias)])
            ->join($foreignTable, $foreignColumn, '=', $ownerColumn, 'left');
    }
protected function loadBelongsTo ( Collection $ relations , BelongsTo $ relationClass , Model $ relationModel , Model $ model , Builder $ query , $ direction ) { $ foreignKey = $ relationClass -> getOwnerKey ( ) ; $ ownerKey = $ relationClass -> getForeignKey ( ) ; $ ownerTable = $ model -> getTable ( ) ; $ foreignTable = $ relationModel -> getTable ( ) ; $ ownerColumn = implode ( '.' , [ $ ownerTable , $ ownerKey ] ) ; $ foreignColumn = implode ( '.' , [ $ foreignTable , $ foreignKey ] ) ; $ sortedColumnRaw = '`' . $ foreignTable . '`.`' . $ relations -> last ( ) . '`' ; $ sortedColumnAlias = implode ( '__' , [ $ foreignTable , $ relations -> last ( ) ] ) ; $ this -> sortedColumnAlias = $ sortedColumnAlias ; $ query -> addSelect ( [ DB :: raw ( $ sortedColumnRaw . ' AS ' . $ sortedColumnAlias ) ] ) -> join ( $ foreignTable , $ foreignColumn , '=' , $ ownerColumn , 'left' ) ; }
Load keys for BelongsTo.
@param Collection $relations
@param BelongsTo $relationClass
@param Model $relationModel
@param Model $model
@param Builder $query
@param $direction
Load keys for BelongsTo .