Skip to content

Commit

Permalink
Merge 4.7 into 4.8 (#3117)
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodb-php-bot authored Aug 27, 2024
2 parents 500ae9b + 62f6449 commit 6a8a2e3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file.

## [4.8.0] - next
## [4.8.0] - 2024-08-27

* Add `Query\Builder::incrementEach()` and `decrementEach()` methods by @SmallRuralDog in [#2550](https://github.com/mongodb/laravel-mongodb/pull/2550)
* Add `Query\Builder::whereLike()` and `whereNotLike()` methods by @GromNaN in [#3108](https://github.com/mongodb/laravel-mongodb/pull/3108)
* Deprecate `Connection::collection()` and `Schema\Builder::collection()` methods by @GromNaN in [#3062](https://github.com/mongodb/laravel-mongodb/pull/3062)
* Deprecate `Model::$collection` property to customize collection name. Use `$table` instead by @GromNaN in [#3064](https://github.com/mongodb/laravel-mongodb/pull/3064)

## [4.7.2] - 2024-08-27

* Add `Query\Builder::upsert()` method with a single document by @GromNaN in [#3100](https://github.com/mongodb/laravel-mongodb/pull/3100)

## [4.7.1] - 2024-07-25

* Fix registration of `BusServiceProvider` for compatibility with Horizon by @GromNaN in [#3071](https://github.com/mongodb/laravel-mongodb/pull/3071)
Expand Down
5 changes: 5 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ public function upsert(array $values, $uniqueBy, $update = null): int
return 0;
}

// Single document provided
if (! array_is_list($values)) {
$values = [$values];
}

$this->applyBeforeQueryCallbacks();

$options = $this->inheritConnectionOptions();
Expand Down
5 changes: 2 additions & 3 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ public function testUpsert()
$this->assertSame('bar2', User::where('email', 'foo')->first()->name);

// If no update fields are specified, all fields are updated
$result = User::upsert([
['email' => 'foo', 'name' => 'bar3'],
], 'email');
// Test single document update
$result = User::upsert(['email' => 'foo', 'name' => 'bar3'], 'email');

$this->assertSame(1, $result);
$this->assertSame(2, User::count());
Expand Down
5 changes: 2 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,8 @@ public function testUpsert()
$this->assertSame('bar2', DB::table('users')->where('email', 'foo')->first()['name']);

// If no update fields are specified, all fields are updated
$result = DB::table('users')->upsert([
['email' => 'foo', 'name' => 'bar3'],
], 'email');
// Test single document update
$result = DB::table('users')->upsert(['email' => 'foo', 'name' => 'bar3'], 'email');

$this->assertSame(1, $result);
$this->assertSame(2, DB::table('users')->count());
Expand Down

0 comments on commit 6a8a2e3

Please sign in to comment.