diff --git a/src/Relations/BelongsToThrough.php b/src/Relations/BelongsToThrough.php index b5ee78a..6846ffc 100644 --- a/src/Relations/BelongsToThrough.php +++ b/src/Relations/BelongsToThrough.php @@ -191,7 +191,11 @@ protected function setRelationQueryConstraints(Builder $query) $one = $model->getQualifiedKeyName(); } - $key = $this->wrap($this->getQualifiedParentKeyName()); + $key = $this->parent + ->newQueryWithoutScopes() + ->getQuery() + ->getGrammar() + ->wrap($this->getQualifiedParentKeyName()); $query->where(new Expression($alias.'.'.$this->getParent()->getKeyName()), '=', new Expression($key)); } @@ -205,7 +209,7 @@ protected function setRelationQueryConstraints(Builder $query) * * @return \Illuminate\Database\Eloquent\Builder */ - public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*']) + public function getRelationExistenceQuery(Builder $query, Builder $parent, $columns = ['*']) { $query->select($columns);