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

Sign up
Appearance settings

Commit bdae18d

Browse files
Merge 5.3 into 5.x (#3349)
2 parents c46ff7f + 9d540b6 commit bdae18d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

‎docs/fundamentals/connection/connection-options.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This guide covers the following topics:
3232

3333
- :ref:`laravel-connection-auth-options`
3434
- :ref:`laravel-driver-options`
35+
- :ref:`laravel-disable-id-alias`
3536

3637
.. _laravel-connection-auth-options:
3738

@@ -349,3 +350,47 @@ item, as shown in the following example:
349350

350351
See the `$driverOptions: array <https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBClient__construct/#parameters>`__
351352
section of the {+php-library+} documentation for a list of driver options.
353+
354+
.. _laravel-disable-id-alias:
355+
356+
Disable Use of id Field Name Conversion
357+
---------------------------------------
358+
359+
Starting in {+odm-long+} v5.0, ``id`` is an alias for the ``_id`` field
360+
in MongoDB documents, and the library automatically converts ``id``
361+
to ``_id`` for both top level and embedded fields when querying and
362+
storing data.
363+
364+
When using {+odm-long+} v5.3 or later, you can disable the automatic
365+
conversion of ``id`` to ``_id`` for embedded documents. To do so,
366+
perform either of the following actions:
367+
368+
1. Set the ``rename_embedded_id_field`` setting to ``false`` in your
369+
``config/database.php`` file:
370+
371+
.. code-block:: php
372+
:emphasize-lines: 6
373+
374+
'connections' => [
375+
'mongodb' => [
376+
'dsn' => 'mongodb+srv://mongodb0.example.com/',
377+
'driver' => 'mongodb',
378+
'database' => 'sample_mflix',
379+
'rename_embedded_id_field' => false,
380+
// Other settings
381+
],
382+
],
383+
384+
#. Pass ``false`` to the ``setRenameEmbeddedIdField()`` method in your
385+
application:
386+
387+
.. code-block:: php
388+
389+
DB::connection('mongodb')->setRenameEmbeddedIdField(false);
390+
391+
.. important::
392+
393+
We recommend using this option only to provide backwards
394+
compatibility with existing document schemas. In new projects,
395+
avoid using ``id`` for field names in embedded documents so that
396+
you can maintain {+odm-long+}'s default behavior.

‎docs/query-builder.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ the value of the ``title`` field is ``"Back to the Future"``:
195195
:start-after: begin query orWhere
196196
:end-before: end query orWhere
197197

198-
.. note::
198+
.. note:: id Alias
199199

200200
You can use the ``id`` alias in your queries to represent the
201201
``_id`` field in MongoDB documents, as shown in the preceding
@@ -208,6 +208,9 @@ the value of the ``title`` field is ``"Back to the Future"``:
208208
Because of this behavior, you cannot have two separate ``id`` and ``_id``
209209
fields in your documents.
210210

211+
To learn how to disable this behavior for embedded documents, see the
212+
:ref:`laravel-disable-id-alias` section of the Connection Options guide.
213+
211214
.. _laravel-query-builder-logical-and:
212215

213216
Logical AND Example

‎docs/upgrade.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ This library version introduces the following breaking changes:
127127
method results before hydrating a Model instance. When passing a complex query
128128
filter, use the ``DB::where()`` method instead of ``Model::raw()``.
129129

130+
Starting in v5.3, you can disable automatic conversion of ``id`` to
131+
``_id`` for embedded documents. To learn more, see the
132+
:ref:`laravel-disable-id-alias` section of the Connection Options
133+
guide.
134+
130135
- Removes support for the ``$collection`` property. The following code shows
131136
how to assign a MongoDB collection to a variable in your ``User`` class in
132137
older versions compared to v5.0:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /