Commit 2263bc4f authored by Ben Argo's avatar Ben Argo

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.
parent 1358e504
......@@ -150,7 +150,7 @@ class Builder extends EloquentBuilder
$relations = $query->pluck($relation->getHasCompareKey());
$relationCount = array_count_values(array_map(function ($id) {
return (string) $id; // Convert Back ObjectIds to Strings
}, is_array($relations) ? $relations : $relations->toArray()));
}, is_array($relations) ? $relations : $relations->flatten()->toArray()));
// Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment