Skip to content

Commit 4766274

Browse files
authored
DOCSP-43159: QB returns objects (#3135)
* DOCSP-43159: QB returns objects * add to upgrade guide * add depth layer * JT tech review 2 * wip
1 parent 6507279 commit 4766274

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

docs/query-builder.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@ testability.
3838

3939
The {+odm-short+} provides the ``DB`` method ``table()`` to access a collection.
4040
Chain methods to specify commands and any constraints. Then, chain
41-
the ``get()`` method at the end to run the methods and retrieve the results.
41+
the ``get()`` method at the end to run the methods and retrieve the
42+
results. To retrieve only the first matching result, chain the
43+
``first()`` method instead of the ``get()`` method. Starting in
44+
{+odm-long+} v5.0, the query builder returns results as ``stdClass`` objects.
45+
4246
The following example shows the syntax of a query builder call:
4347

4448
.. code-block:: php
4549

4650
DB::table('<collection name>')
4751
// chain methods by using the "->" object operator
4852
->get();
49-
.. tip::
53+
54+
.. tip:: Set Database Connection
5055

5156
Before using the ``DB::table()`` method, ensure that you specify MongoDB as your application's
5257
default database connection. For instructions on setting the database connection,

docs/upgrade.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Upgrade Library Version
1414
.. contents:: On this page
1515
:local:
1616
:backlinks: none
17-
:depth: 1
17+
:depth: 2
1818
:class: singlecol
1919

2020
Overview
@@ -71,6 +71,26 @@ Version 5.x Breaking Changes
7171

7272
This library version introduces the following breaking changes:
7373

74+
- The query builder returns results as as ``stdClass`` objects instead
75+
of as arrays. This change requires that you change array access to
76+
property access when interacting with query results.
77+
78+
The following code shows how to retrieve a query result and access a
79+
property from the result object in older versions compared to v5.0:
80+
81+
.. code-block:: php
82+
:emphasize-lines: 8-9
83+
84+
$document = DB::table('accounts')
85+
->where('name', 'Anita Charles')
86+
->first();
87+
88+
// older versions
89+
$document['balance'];
90+
91+
// v5.0
92+
$document->balance;
93+
7494
- Removes support for the following classes:
7595

7696
- ``MongoDB\Laravel\Auth\DatabaseTokenRepository``. Instead, use the default

0 commit comments

Comments
 (0)