Skip to content

Commit 91e0f6a

Browse files
committed
DOCSP-41335: Id alias
1 parent 6cebcec commit 91e0f6a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

docs/fundamentals/read-operations.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ This example queries for documents in which the value of the ``runtime`` field i
552552
``30`` and returns the first matching document according to the value of the ``_id``
553553
field.
554554

555+
.. note::
556+
557+
This example uses the ``id`` alias to represent the ``_id`` field, since {+odm-short+}
558+
converts from ``id`` to ``_id`` automatically.
559+
555560
.. tabs::
556561

557562
.. tab:: Query Syntax
@@ -582,7 +587,7 @@ field.
582587
public function show()
583588
{
584589
$movie = Movie::where('runtime', 30)
585-
->orderBy('_id')
590+
->orderBy('id')
586591
->first();
587592

588593
return view('browse_movies', [

docs/includes/query-builder/QueryBuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use MongoDB\BSON\Regex;
1111
use MongoDB\Laravel\Collection;
1212
use MongoDB\Laravel\Tests\TestCase;
13+
use MongoDB\BSON\ObjectId;
1314

1415
use function file_get_contents;
1516
use function json_decode;
@@ -63,7 +64,7 @@ public function testOrWhere(): void
6364
// begin query orWhere
6465
$result = DB::connection('mongodb')
6566
->collection('movies')
66-
->where('year', 1955)
67+
->where('id', new ObjectId('573a1398f29313caabce9682'))
6768
->orWhere('title', 'Back to the Future')
6869
->get();
6970
// end query orWhere

docs/query-builder.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,23 @@ Logical OR Example
176176

177177
The following example shows how to chain the ``orWhere()``
178178
query builder method to retrieve documents from the
179-
``movies`` collection that either match the ``year``
180-
value of ``1955`` or match the ``title`` value ``"Back to the Future"``:
179+
``movies`` collection that either match the ``_id``
180+
value of ``ObjectId('573a1398f29313caabce9682')`` or match
181+
the ``title`` value ``"Back to the Future"``:
181182

182183
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
183184
:language: php
184185
:dedent:
185186
:start-after: begin query orWhere
186187
:end-before: end query orWhere
187188

189+
.. note::
190+
191+
Beginning in {+odm-short+} v4.6, you can use the ``id`` alias to
192+
represent the ``_id`` field, as shown in the preceding code. When you
193+
run a find operation using the query builder, {+odm-short+}
194+
automatically converts between ``id`` and ``_id``.
195+
188196
.. _laravel-query-builder-logical-and:
189197

190198
Logical AND Example

0 commit comments

Comments
 (0)