File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff 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,22 @@ item, as shown in the following example:
349350
350351See the `$driverOptions: array <https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBClient__construct/#parameters>`__
351352section 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, set
366+ the ``renameEmbeddedIdField`` connection setting to ``false``, as
367+ shown in the following code:
368+
369+ .. code-block:: php
370+
371+ DB::connection('mongodb')->setRenameEmbeddedIdField(false);
Original file line number Diff line number Diff 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
213216Logical AND Example
You can’t perform that action at this time.
0 commit comments