Skip to content

DOCSP-43159: QB returns objects #3135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ testability.

The {+odm-short+} provides the ``DB`` method ``table()`` to access a collection.
Chain methods to specify commands and any constraints. Then, chain
the ``get()`` method at the end to run the methods and retrieve the results.
the ``get()`` method at the end to run the methods and retrieve the
results. To retrieve only the first matching result, chain the
``first()`` method instead of the ``get()`` method. Starting in
{+odm-long+} v5.0, the query builder returns results as objects.

The following example shows the syntax of a query builder call:

.. code-block:: php

DB::table('<collection name>')
// chain methods by using the "->" object operator
->get();
.. tip::

.. tip:: Set Database Connection

Before using the ``DB::table()`` method, ensure that you specify MongoDB as your application's
default database connection. For instructions on setting the database connection,
Expand Down
17 changes: 16 additions & 1 deletion docs/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Upgrade Library Version
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:depth: 2
:class: singlecol

Overview
Expand Down Expand Up @@ -71,6 +71,21 @@ Version 5.x Breaking Changes

This library version introduces the following breaking changes:

- The query builder returns results as objects, instead of as arrays.
This change requires that you change array access to property access
when interacting with query results.

The following code shows how to retrieve a query result and access a
property from the result object:

.. code-block:: php
:emphasize-lines: 4

DB::table('accounts')
->where('name', 'Anita Charles')
->first()
->balance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could highlight the change with a diff (not sure if diffs are correctly colorized in the docs):

Suggested change
DB::table('accounts')
->where('name', 'Anita Charles')
->first()
->balance
$document = DB::table('accounts')
->where('name', 'Anita Charles')
->first();
- $document['balance'];
+ $document->balance;

Preview:

     $document = DB::table('accounts')
         ->where('name', 'Anita Charles')
         ->first();

-    $document['balance'];
+    $document->balance;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way we can demonstrate this is by using code comments. I can make that change though!


- In query results, the library converts BSON ``UTCDateTime`` objects to ``Carbon``
date classes, applying the default timezone.

Expand Down
Loading