Skip to content

Commit 0fc7c47

Browse files
author
Pooya Parsa
committed
check $relations is array
1 parent b6af2be commit 0fc7c47

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Jenssegers/Mongodb/Eloquent/Builder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
44
use Illuminate\Database\Eloquent\Relations\Relation;
5+
use Illuminate\Support\Collection;
56
use MongoDB\Driver\Cursor;
67
use MongoDB\Model\BSONDocument;
78

@@ -167,9 +168,10 @@ protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $o
167168
$query = $hasQuery->getQuery();
168169

169170
// Get the number of related objects for each possible parent.
171+
$relations = $query->pluck($relation->getHasCompareKey());
170172
$relationCount = array_count_values(array_map(function ($id) {
171173
return (string) $id; // Convert Back ObjectIds to Strings
172-
}, $query->pluck($relation->getHasCompareKey())));
174+
}, is_array($relations) ? $relations : $relations->toArray()));
173175

174176
// Remove unwanted related objects based on the operator and count.
175177
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) {

0 commit comments

Comments
 (0)