protected function getCachedRelationship(string $relation, $result, Relationship $relationship)
    {
        $pivotColumns = $relationship->getPivotAttributes();

        if (!array_key_exists($relation, $this->pivotAttributes)) {
            $this->pivotAttributes[$relation] = $pivotColumns;
        }

        $wrapper = $this->factory->make($result);

        $hash = $wrapper->getEntityHash();

        if (count($pivotColumns) > 0) {
            $pivotAttributes = [];
            foreach ($pivotColumns as $column) {
                $pivot = $wrapper->getEntityAttribute('pivot');

                $pivotWrapper = $this->factory->make($pivot);

                $pivotAttributes[$column] = $pivotWrapper->getEntityAttribute($column);
            }

            $cachedRelationship = new CachedRelationship($hash, $pivotAttributes);
        } else {
            $cachedRelationship = new CachedRelationship($hash);
        }

        return $cachedRelationship;
    }
protected function getCachedRelationship(string $relation, $result, Relationship $relationship)
    {
        $pivotColumns = $relationship->getPivotAttributes();

        if (!array_key_exists($relation, $this->pivotAttributes)) {
            $this->pivotAttributes[$relation] = $pivotColumns;
        }

        $wrapper = $this->factory->make($result);

        $hash = $wrapper->getEntityHash();

        if (count($pivotColumns) > 0) {
            $pivotAttributes = [];
            foreach ($pivotColumns as $column) {
                $pivot = $wrapper->getEntityAttribute('pivot');

                $pivotWrapper = $this->factory->make($pivot);

                $pivotAttributes[$column] = $pivotWrapper->getEntityAttribute($column);
            }

            $cachedRelationship = new CachedRelationship($hash, $pivotAttributes);
        } else {
            $cachedRelationship = new CachedRelationship($hash);
        }

        return $cachedRelationship;
    }
protected function getCachedRelationship ( string $ relation , $ result , Relationship $ relationship ) { $ pivotColumns = $ relationship -> getPivotAttributes ( ) ; if ( ! array_key_exists ( $ relation , $ this -> pivotAttributes ) ) { $ this -> pivotAttributes [ $ relation ] = $ pivotColumns ; } $ wrapper = $ this -> factory -> make ( $ result ) ; $ hash = $ wrapper -> getEntityHash ( ) ; if ( count ( $ pivotColumns ) > 0 ) { $ pivotAttributes = [ ] ; foreach ( $ pivotColumns as $ column ) { $ pivot = $ wrapper -> getEntityAttribute ( 'pivot' ) ; $ pivotWrapper = $ this -> factory -> make ( $ pivot ) ; $ pivotAttributes [ $ column ] = $ pivotWrapper -> getEntityAttribute ( $ column ) ; } $ cachedRelationship = new CachedRelationship ( $ hash , $ pivotAttributes ) ; } else { $ cachedRelationship = new CachedRelationship ( $ hash ) ; } return $ cachedRelationship ; }
Create a cachedRelationship instance which will hold related entity's hash and pivot attributes, if any.

@param string       $relation
@param array        $result
@param Relationship $relationship

@throws MappingException

@return CachedRelationship
Create a cachedRelationship instance which will hold related entity s hash and pivot attributes if any .