Skip to content

Commit

Permalink
#1930 assert that a instance of the Mongo query builder is used
Browse files Browse the repository at this point in the history
The base `update(..)` method and the MongoDB `update(..)` differ in the amount of arguments.
Adding a assertion to make sure the correct one is used.
  • Loading branch information
Treggats committed Nov 4, 2023
1 parent 5971522 commit 06a405f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use MongoDB\Driver\Cursor;
use MongoDB\Laravel\Helpers\QueriesRelationships;
use MongoDB\Laravel\Query\Builder as MongoDBQueryBuilder;
use MongoDB\Model\BSONDocument;

use function array_key_exists;
use function array_merge;
use function assert;
use function collect;
use function is_array;
use function iterator_to_array;
Expand Down Expand Up @@ -71,7 +73,10 @@ public function update(array $values, array $options = [])
return 1;
}

return $this->toBase()->update($this->addUpdatedAtColumn($values), $options);
$builder = $this->toBase();
assert($builder instanceof MongoDBQueryBuilder);

return $builder->update($this->addUpdatedAtColumn($values), $options);
}

/** @inheritdoc */
Expand Down

0 comments on commit 06a405f

Please sign in to comment.