Skip to content

Commit

Permalink
Merge 4.8 into 5.0 (#3120)
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodb-php-bot authored Aug 27, 2024
2 parents 457971b + aaf3982 commit f1ffd1b
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
Expand Up @@ -5,13 +5,17 @@ All notable changes to this project will be documented in this file.

* **BREAKING CHANGE** Use `id` as an alias for `_id` in commands and queries for compatibility with Eloquent packages by @GromNaN in [#3040](https://github.com/mongodb/laravel-mongodb/pull/3040)

## [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 @@ -746,6 +746,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 @@ -633,9 +633,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 f1ffd1b

Please sign in to comment.