Skip to content

Commit 61c0662

Browse files
committed
Fix array to string conversion
With ‘BelongsToMany’ relationships calling the function `Jenssegers\Mongodb\Eloquent\Model::has` can throw an ErrorException with ‘Array to string conversion’. By flattening the collection here we can avoid triggering the exception.
1 parent 6944c06 commit 61c0662

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Jenssegers/Mongodb/Eloquent/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $o
150150
$relations = $query->pluck($relation->getHasCompareKey());
151151
$relationCount = array_count_values(array_map(function ($id) {
152152
return (string) $id; // Convert Back ObjectIds to Strings
153-
}, is_array($relations) ? $relations : $relations->toArray()));
153+
}, is_array($relations) ? $relations : $relations->flatten()->toArray()));
154154

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

0 commit comments

Comments
 (0)