Skip to content

Commit 8215cfb

Browse files
committed
Eloquent: support HasOneThrough relationships
1 parent dbd3cee commit 8215cfb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Adapter/EloquentAdapter.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,14 @@ public function filterByAttribute($query, Attribute $attribute, $value, string $
167167
public function filterByHasOne($query, HasOne $relationship, array $ids): void
168168
{
169169
$relation = $this->getEloquentRelation($query->getModel(), $relationship);
170-
$column = $relation instanceof HasOneThrough
171-
? $relation->getQualifiedParentKeyName()
172-
: $relation->getQualifiedForeignKeyName();
173170

174-
$query->whereIn($column, $ids);
171+
if ($relation instanceof HasOneThrough) {
172+
$query->whereHas($this->getRelationshipProperty($relationship), function ($query) use ($relation, $ids) {
173+
$query->whereIn($relation->getQualifiedParentKeyName(), $ids);
174+
});
175+
} else {
176+
$query->whereIn($relation->getQualifiedForeignKeyName(), $ids);
177+
}
175178
}
176179

177180
public function filterByHasMany($query, HasMany $relationship, array $ids): void

0 commit comments

Comments
 (0)