Commit 0fc7c470 authored by Pooya Parsa's avatar Pooya Parsa

check $relations is array

parent b6af2bea
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Collection;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
...@@ -167,9 +168,10 @@ class Builder extends EloquentBuilder ...@@ -167,9 +168,10 @@ class Builder extends EloquentBuilder
$query = $hasQuery->getQuery(); $query = $hasQuery->getQuery();
// Get the number of related objects for each possible parent. // Get the number of related objects for each possible parent.
$relations = $query->pluck($relation->getHasCompareKey());
$relationCount = array_count_values(array_map(function ($id) { $relationCount = array_count_values(array_map(function ($id) {
return (string) $id; // Convert Back ObjectIds to Strings return (string) $id; // Convert Back ObjectIds to Strings
}, $query->pluck($relation->getHasCompareKey()))); }, is_array($relations) ? $relations : $relations->toArray()));
// Remove unwanted related objects based on the operator and count. // Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) { $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