Skip to content

Commit f1ffd1b

Browse files
Merge 4.8 into 5.0 (#3120)
2 parents 457971b + aaf3982 commit f1ffd1b

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ All notable changes to this project will be documented in this file.
55

66
* **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)
77

8-
## [4.8.0] - next
8+
## [4.8.0] - 2024-08-27
99

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

15+
## [4.7.2] - 2024-08-27
16+
17+
* Add `Query\Builder::upsert()` method with a single document by @GromNaN in [#3100](https://github.com/mongodb/laravel-mongodb/pull/3100)
18+
1519
## [4.7.1] - 2024-07-25
1620

1721
* Fix registration of `BusServiceProvider` for compatibility with Horizon by @GromNaN in [#3071](https://github.com/mongodb/laravel-mongodb/pull/3071)

src/Query/Builder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,11 @@ public function upsert(array $values, $uniqueBy, $update = null): int
746746
return 0;
747747
}
748748

749+
// Single document provided
750+
if (! array_is_list($values)) {
751+
$values = [$values];
752+
}
753+
749754
$this->applyBeforeQueryCallbacks();
750755

751756
$options = $this->inheritConnectionOptions();

tests/ModelTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ public function testUpsert()
168168
$this->assertSame('bar2', User::where('email', 'foo')->first()->name);
169169

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

175174
$this->assertSame(1, $result);
176175
$this->assertSame(2, User::count());

tests/QueryBuilderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,8 @@ public function testUpsert()
633633
$this->assertSame('bar2', DB::table('users')->where('email', 'foo')->first()['name']);
634634

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

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

0 commit comments

Comments
 (0)