Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 ``stdClass`` 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
22 changes: 21 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,26 @@ Version 5.x Breaking Changes

This library version introduces the following breaking changes:

- The query builder returns results as as ``stdClass`` 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 in older versions compared to v5.0:

.. code-block:: php
:emphasize-lines: 8-9

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

// older versions
$document['balance'];

// v5.0
$document->balance;

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

Expand Down