Skip to content

Commit 70ff6e6

Browse files
committed
JT tech review 1
1 parent c5c84af commit 70ff6e6

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

docs/fundamentals/write-operations.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,14 @@ the following methods:
272272
Upsert Method
273273
~~~~~~~~~~~~~
274274

275-
The ``upsert()`` query builder method accepts the following parameters:
275+
The ``upsert(array $values, array|string $uniqueBy, array|null
276+
$update)`` method accepts the following parameters:
276277

277-
- Array of fields and values that specify documents to update or insert.
278-
- Array of fields that uniquely identify documents in your first array parameter.
279-
- Array of fields to update if a matching document exists. If you omit
280-
this parameter, {+odm-short+} updates all fields.
278+
- ``$values``: Array of fields and values that specify documents to update or insert.
279+
- ``$uniqueBy``: List of fields that uniquely identify documents in your
280+
first array parameter.
281+
- ``$update``: Optional list of fields to update if a matching document
282+
exists. If you omit this parameter, {+odm-short+} updates all fields.
281283

282284
To specify an upsert in the ``upsert()`` method, set parameters
283285
as shown in the following code example:
@@ -287,7 +289,8 @@ as shown in the following code example:
287289

288290
YourModel::upsert(
289291
[/* documents to update or insert */],
290-
'/* unique field */', [/* fields to update */]
292+
'/* unique field */',
293+
[/* fields to update */],
291294
);
292295

293296
Example

docs/query-builder.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,14 @@ the following query builder methods:
10491049
Upsert Method
10501050
^^^^^^^^^^^^^
10511051

1052-
The ``upsert()`` query builder method accepts the following parameters:
1052+
The ``upsert(array $values, array|string $uniqueBy, array|null
1053+
$update)`` query builder method accepts the following parameters:
10531054

1054-
- Array of fields and values that specify documents to update or insert.
1055-
- Array of fields that uniquely identify documents in your first array parameter.
1056-
- Array of fields to update if a matching document exists. If you omit
1057-
this parameter, {+odm-short+} updates all fields.
1055+
- ``$values``: Array of fields and values that specify documents to update or insert.
1056+
- ``$uniqueBy``: List of fields that uniquely identify documents in your
1057+
first array parameter.
1058+
- ``$update``: Optional list of fields to update if a matching document
1059+
exists. If you omit this parameter, {+odm-short+} updates all fields.
10581060

10591061
The following example shows how to use the ``upsert()`` query builder method
10601062
to update or insert documents based on the following instructions:
@@ -1081,6 +1083,12 @@ to update or insert documents based on the following instructions:
10811083
The ``upsert()`` query builder method returns the number of
10821084
documents that the operation updated, inserted, and modified.
10831085

1086+
.. note::
1087+
1088+
The ``upsert()`` method does not trigger events. To trigger events
1089+
from an upsert operation, you can use the ``createOrFirst()`` method
1090+
instead.
1091+
10841092
Update Method
10851093
^^^^^^^^^^^^^
10861094

0 commit comments

Comments
 (0)