protected function newPivotQuery(BelongsToMany $relation)
    {
        $query = $relation->newPivotStatement()->where(
            $this->getForeignPivotKeyName($relation),
            $relation->getParent()->getKey()
        );

        return Models::scope()->applyToRelationQuery(
            $query, $relation->getTable()
        );
    }