File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -552,6 +552,11 @@ This example queries for documents in which the value of the ``runtime`` field i
552
552
``30`` and returns the first matching document according to the value of the ``_id``
553
553
field.
554
554
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
+
555
560
.. tabs::
556
561
557
562
.. tab:: Query Syntax
@@ -582,7 +587,7 @@ field.
582
587
public function show()
583
588
{
584
589
$movie = Movie::where('runtime', 30)
585
- ->orderBy('_id ')
590
+ ->orderBy('id ')
586
591
->first();
587
592
588
593
return view('browse_movies', [
Original file line number Diff line number Diff line change 10
10
use MongoDB \BSON \Regex ;
11
11
use MongoDB \Laravel \Collection ;
12
12
use MongoDB \Laravel \Tests \TestCase ;
13
+ use MongoDB \BSON \ObjectId ;
13
14
14
15
use function file_get_contents ;
15
16
use function json_decode ;
@@ -63,7 +64,7 @@ public function testOrWhere(): void
63
64
// begin query orWhere
64
65
$ result = DB ::connection ('mongodb ' )
65
66
->collection ('movies ' )
66
- ->where ('year ' , 1955 )
67
+ ->where ('id ' , new ObjectId ( ' 573a1398f29313caabce9682 ' ) )
67
68
->orWhere ('title ' , 'Back to the Future ' )
68
69
->get ();
69
70
// end query orWhere
Original file line number Diff line number Diff line change @@ -176,15 +176,23 @@ Logical OR Example
176
176
177
177
The following example shows how to chain the ``orWhere()``
178
178
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"``:
181
182
182
183
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
183
184
:language: php
184
185
:dedent:
185
186
:start-after: begin query orWhere
186
187
:end-before: end query orWhere
187
188
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
+
188
196
.. _laravel-query-builder-logical-and:
189
197
190
198
Logical AND Example
You can’t perform that action at this time.
0 commit comments