Skip to content

Commit 8430d1c

Browse files
author
Chris Cho
committed
PRR fixes
1 parent 70310ef commit 8430d1c

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

docs/eloquent-models.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ Eloquent Models
1212
:keywords: php framework, odm
1313

1414
Eloquent models are part of the Laravel Eloquent object-relational
15-
mapping (ORM) framework that enable you to work with a database by using
16-
model classes. The {+odm-short+} extends this framework to use similar
17-
syntax to work with MongoDB as a database.
15+
mapping (ORM) framework, which lets you to work with data in a relational
16+
database by using model classes and Eloquent syntax. {+odm-short+} extends
17+
this framework so that you can use Eloquent syntax to work with data in a
18+
MongoDB database.
1819

1920
This section contains guidance on how to use Eloquent models in
2021
{+odm-short+} to work with MongoDB in the following ways:
2122

22-
- :ref:`laravel-eloquent-model-relationships` shows how to add relationships
23+
- :ref:`laravel-eloquent-model-relationships` shows how to define relationships
2324
between models
2425

2526
.. toctree::

docs/eloquent-models/relationships.txt

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ Eloquent Model Relationships
1414
Overview
1515
--------
1616

17+
When you use a relational database, the Eloquent ORM stores models as rows
18+
in tables that correspond to the model classes. When you use MongoDB, the
19+
{+odm-short+} stores models as documents in collections that correspond to the
20+
model classes.
21+
22+
To define a relationship, add a function to the model class that calls the
23+
appropriate relationship method. This function allows you to access the related
24+
model as a **dynamic property**. A dynamic property lets you access the
25+
related model by using the same syntax as you use to access a property on the
26+
model.
27+
1728
This page describes the following Laravel Eloquent and MongoDB-specific
1829
relationships available in {+odm-short+} and shows examples of how to define
1930
and use them:
@@ -30,24 +41,19 @@ and use them:
3041
- :ref:`Cross-database relationships <laravel-relationship-cross-database>`,
3142
required when you want to create relationships between MongoDB and SQL models
3243

33-
Add a function to the model class that calls the appropriate relationship method
34-
to establish a relationship. This function allows you to access the related
35-
model as a **dynamic property**. A dynamic property lets you access the
36-
related model by using the same syntax as you use to access a property on the
37-
model.
38-
3944
.. _laravel-eloquent-relationship-one-to-one:
4045

4146
One to One Relationship
4247
-----------------------
4348

4449
A one to one relationship between models consists of a model record related to
45-
exactly one other type of model record. In MongoDB, a record is represented as
50+
exactly one other type of model record.
51+
4652
a document, and different model types exist in separate collections.
4753

48-
When you add a one to one relationship by using the method, Eloquent lets you
49-
access the model by using a dynamic property and stores the model's document
50-
ID on the related model.
54+
When you add a one to one relationship, Eloquent lets you access the model by
55+
using a dynamic property and stores the model's document ID on the related
56+
model.
5157

5258
In {+odm-short+}, you can define a one to one relationship by using the
5359
``hasOne()`` method or ``belongsTo()`` method.
@@ -58,7 +64,7 @@ does not add any fields.
5864

5965
To learn more about one to one relationships, see
6066
`One to One <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-relationships#one-to-one>`__
61-
in the Laravel docs.
67+
in the Laravel documentation.
6268

6369
One to One Example
6470
~~~~~~~~~~~~~~~~~~
@@ -70,16 +76,15 @@ relationship between a ``Planet`` and ``Orbit`` model.
7076
:language: php
7177
:dedent:
7278

73-
The following example class uses a dynamic property and calls the
74-
``belongsTo()`` method to define the inverse of the relationship on ``Orbit``
75-
as shown in the following example class:
79+
The following example class shows how to define the inverse relationship with
80+
``Orbit`` by using the ``belongsTo()`` method:
7681

7782
.. literalinclude:: /includes/eloquent-models/relationships/OrbitOneToOne.php
7883
:language: php
7984
:dedent:
8085

8186
The following sample code shows how to instantiate a model for each class
82-
and add the relationship between them. Click the :guilabel:`View Output`
87+
and add the relationship between them. Click the :guilabel:`View Output`
8388
button to see the data created by running the code:
8489

8590
.. io-code-block::
@@ -142,7 +147,7 @@ without adding any fields.
142147

143148
To learn more about one to many relationships, see
144149
`One to Many <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-relationships#one-to-many>`__
145-
in the Laravel docs.
150+
in the Laravel documentation.
146151

147152
One to Many Example
148153
~~~~~~~~~~~~~~~~~~~
@@ -163,7 +168,7 @@ example class:
163168
:dedent:
164169

165170
The following sample code shows how ton instantiate a model for each class
166-
and add the relationship between them. Click the :guilabel:`View Output`
171+
and add the relationship between them. Click the :guilabel:`View Output`
167172
button to see the data created by running the code:
168173

169174
.. io-code-block::
@@ -213,7 +218,6 @@ the dynamic properties as defined in the example classes.
213218
:start-after: begin planet moons dynamic property example
214219
:end-before: end planet moons dynamic property example
215220

216-
217221
.. _laravel-eloquent-relationship-many-to-many:
218222

219223
Many to Many Relationship
@@ -239,7 +243,7 @@ document field, derived from the related model class name.
239243

240244
To learn more about many to many relationships in Laravel, see
241245
`Many to Many <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-relationships#many-to-many>`__
242-
in the Laravel docs.
246+
in the Laravel documentation.
243247

244248
The following section shows an example of how to create a many to many
245249
relationship between model classes.
@@ -262,7 +266,7 @@ relationship with ``Planet`` as shown in the following example class:
262266
:dedent:
263267

264268
The following sample code shows how to instantiate a model for each class
265-
and add the relationship between them. Click the :guilabel:`View Output`
269+
and add the relationship between them. Click the :guilabel:`View Output`
266270
button to see the data created by running the code:
267271

268272
.. io-code-block::
@@ -339,20 +343,19 @@ the dynamic properties as defined in the example classes.
339343
:start-after: begin many-to-many dynamic property example
340344
:end-before: end many-to-many dynamic property example
341345

342-
343346
.. _laravel-embedded-document-pattern:
344347

345348
Embedded Document Pattern
346349
-------------------------
347350

348351
In MongoDB, the embedded document pattern adds the related model's data into
349-
the parent model instead of keeping foreign key references. This pattern
350-
when you must optimize for one or more of the following requirements:
352+
the parent model instead of keeping foreign key references. Use this pattern
353+
to meet one or more of the following requirements:
351354

352-
- Keep associated data together in a single collection
353-
- Perform atomic updates on multiple fields of the document and the associated
355+
- Keeping associated data together in a single collection
356+
- Performing atomic updates on multiple fields of the document and the associated
354357
data
355-
- Reduce the number of reads required to fetch the data
358+
- Reducing the number of reads required to fetch the data
356359

357360
In {+odm-short+}, you can define embedded documents by using one of the
358361
following dynamic property methods:
@@ -393,7 +396,7 @@ following example class:
393396

394397
The following sample code shows how to create a ``SpaceShip`` model and
395398
embed multiple ``Cargo`` models and the MongoDB document created by running the
396-
code. Click the :guilabel:`View Output` button to see the data created by
399+
code. Click the :guilabel:`View Output` button to see the data created by
397400
running the code:
398401

399402
.. io-code-block::
@@ -473,7 +476,7 @@ The ``Passenger`` model defines a ``BelongsToMany`` relationship with
473476

474477
The following sample code shows how to create a ``SpaceShip`` model in
475478
a MySQL database and related ``Passenger`` models in a MongoDB database and
476-
the data created by running the code. Click the :guilabel:`View Output` button
479+
the data created by running the code. Click the :guilabel:`View Output` button
477480
to see the data created by running the code:
478481

479482
.. io-code-block::

0 commit comments

Comments
 (0)