Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6a8a2e3

Browse filesBrowse files
Merge 4.7 into 4.8 (#3117)
2 parents 500ae9b + 62f6449 commit 6a8a2e3
Copy full SHA for 6a8a2e3

File tree

Expand file treeCollapse file tree

4 files changed

+14
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+14
-7
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [4.8.0] - next
4+
## [4.8.0] - 2024-08-27
55

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

11+
## [4.7.2] - 2024-08-27
12+
13+
* Add `Query\Builder::upsert()` method with a single document by @GromNaN in [#3100](https://github.com/mongodb/laravel-mongodb/pull/3100)
14+
1115
## [4.7.1] - 2024-07-25
1216

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

‎src/Query/Builder.php

Copy file name to clipboardExpand all lines: src/Query/Builder.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ public function upsert(array $values, $uniqueBy, $update = null): int
732732
return 0;
733733
}
734734

735+
// Single document provided
736+
if (! array_is_list($values)) {
737+
$values = [$values];
738+
}
739+
735740
$this->applyBeforeQueryCallbacks();
736741

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

‎tests/ModelTest.php

Copy file name to clipboardExpand all lines: tests/ModelTest.php
+2-3Lines 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

Copy file name to clipboardExpand all lines: tests/QueryBuilderTest.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,8 @@ public function testUpsert()
632632
$this->assertSame('bar2', DB::table('users')->where('email', 'foo')->first()['name']);
633633

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

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.