@@ -21,7 +21,7 @@ Overview
21
21
--------
22
22
23
23
When you use a relational database, the Eloquent ORM stores models as rows
24
- in tables that correspond to the model classes. When you use MongoDB, the
24
+ in tables that correspond to the model classes. When you use MongoDB, the
25
25
{+odm-short+} stores models as documents in collections that correspond to the
26
26
model classes.
27
27
@@ -74,21 +74,23 @@ One to One Example
74
74
~~~~~~~~~~~~~~~~~~
75
75
76
76
The following example class shows how to define a ``HasOne`` one to one
77
- relationship between a ``Planet`` and ``Orbit`` model.
77
+ relationship between a ``Planet`` and ``Orbit`` model by using the
78
+ ``hasOne()`` method:
78
79
79
80
.. literalinclude:: /includes/eloquent-models/relationships/one-to-one/Planet.php
80
81
:language: php
81
82
:dedent:
82
83
83
- The following example class shows how to define the inverse relationship with
84
- ``Orbit`` by using the ``belongsTo()`` method:
84
+ The following example class shows how to define the inverse ``BelongsTo``
85
+ relationship between ``Orbit`` and ``Planet`` by using the ``belongsTo()``
86
+ method:
85
87
86
88
.. literalinclude:: /includes/eloquent-models/relationships/one-to-one/Orbit.php
87
89
:language: php
88
90
:dedent:
89
91
90
92
The following sample code shows how to instantiate a model for each class
91
- and add the relationship between them. Click the :guilabel:`View Output `
93
+ and add the relationship between them. Click the :guilabel:`VIEW OUTPUT `
92
94
button to see the data created by running the code:
93
95
94
96
.. io-code-block::
@@ -157,22 +159,23 @@ One to Many Example
157
159
~~~~~~~~~~~~~~~~~~~
158
160
159
161
The following example class shows how to define a ``HasMany`` one to many
160
- relationship between a ``Planet`` parent model and ``Moon`` child model.
162
+ relationship between a ``Planet`` parent model and ``Moon`` child model by
163
+ using the ``hasMany()`` method:
161
164
162
165
.. literalinclude:: /includes/eloquent-models/relationships/one-to-many/Planet.php
163
166
:language: php
164
167
:dedent:
165
168
166
- To define the inverse of the relationship on ``Moon``, add the dynamic
167
- property and call the ``belongsTo() `` method on it, as shown in the following
168
- example class :
169
+ The following example class shows how to define the inverse ``BelongsTo``
170
+ relationship between a ``Moon `` child model and the and the ``Planet`` parent
171
+ model by using the ``belongsTo()`` method :
169
172
170
173
.. literalinclude:: /includes/eloquent-models/relationships/one-to-many/Moon.php
171
174
:language: php
172
175
:dedent:
173
176
174
- The following sample code shows how ton instantiate a model for each class
175
- and add the relationship between them. Click the :guilabel:`View Output `
177
+ The following sample code shows how to instantiate a model for each class
178
+ and add the relationship between them. Click the :guilabel:`VIEW OUTPUT `
176
179
button to see the data created by running the code:
177
180
178
181
.. io-code-block::
@@ -228,8 +231,8 @@ Many to Many Relationship
228
231
-------------------------
229
232
230
233
A many to many relationship consists of a relationship between two different
231
- model types in which one type of model record can be related to multiple
232
- records of the other type.
234
+ model types in which, for each type of model, an instance of the model can
235
+ be related to multiple instances of the other type.
233
236
234
237
In {+odm-short+}, you can define a many to many relationship by adding the
235
238
``belongsToMany()`` method to both related classes.
@@ -255,22 +258,24 @@ relationship between model classes.
255
258
Many to Many Example
256
259
~~~~~~~~~~~~~~~~~~~~
257
260
258
- The following ``Planet`` class shows how to define a ``BelongsToMany`` many to
259
- many relationship with and a ``SpaceExplorer`` model.
261
+ The following example class shows how to define a ``BelongsToMany`` many to
262
+ many relationship between a ``Planet`` and ``SpaceExporer`` model by using
263
+ the ``belongsToMany()`` method:
260
264
261
265
.. literalinclude:: /includes/eloquent-models/relationships/many-to-many/Planet.php
262
266
:language: php
263
267
:dedent:
264
268
265
- The ``SpaceExplorer`` model defines a ``BelongsToMany`` many to many
266
- relationship with ``Planet`` as shown in the following example class:
269
+ The following example class shows how to define the inverse ``BelongsToMany``
270
+ many to many relationship between a ``SpaceExplorer`` and ``Planet`` model by
271
+ using the ``belongsToMany()`` method:
267
272
268
273
.. literalinclude:: /includes/eloquent-models/relationships/many-to-many/SpaceExplorer.php
269
274
:language: php
270
275
:dedent:
271
276
272
277
The following sample code shows how to instantiate a model for each class
273
- and add the relationship between them. Click the :guilabel:`View Output `
278
+ and add the relationship between them. Click the :guilabel:`VIEW OUTPUT `
274
279
button to see the data created by running the code:
275
280
276
281
.. io-code-block::
@@ -391,15 +396,15 @@ relationship between a ``SpaceShip`` and ``Cargo`` model:
391
396
:dedent:
392
397
393
398
The embedded model class omits the relationship definition as shown in the
394
- following example class:
399
+ following ``Cargo`` model class:
395
400
396
401
.. literalinclude:: /includes/eloquent-models/relationships/embeds/Cargo.php
397
402
:language: php
398
403
:dedent:
399
404
400
405
The following sample code shows how to create a ``SpaceShip`` model and
401
406
embed multiple ``Cargo`` models and the MongoDB document created by running the
402
- code. Click the :guilabel:`View Output ` button to see the data created by
407
+ code. Click the :guilabel:`VIEW OUTPUT ` button to see the data created by
403
408
running the code:
404
409
405
410
.. io-code-block::
@@ -462,16 +467,17 @@ relationship.
462
467
Cross-Database Relationship Example
463
468
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464
469
465
- The following example class creates a ``hasMany `` relationship between a
466
- ``SpaceShip`` model stored in a relational database and a ``Passenger`` model
467
- stored in a MongoDB database:
470
+ The following example class shows how to define a ``HasMany `` relationship
471
+ between a ``SpaceShip`` model stored in a relational database and a
472
+ ``Passenger`` model stored in a MongoDB database:
468
473
469
474
.. literalinclude:: /includes/eloquent-models/relationships/cross-db/SpaceShip.php
470
475
:language: php
471
476
:dedent:
472
477
473
- The ``Passenger`` model defines a ``BelongsToMany`` relationship with
474
- ``SpaceShip`` as shown in the following example class:
478
+ The following example class shows how to define the inverse ``BelongsTo``
479
+ relationship between a ``Passenger`` model and the and the ``Spaceship``
480
+ model by using the ``belongsTo()`` method:
475
481
476
482
.. literalinclude:: /includes/eloquent-models/relationships/cross-db/Passenger.php
477
483
:language: php
@@ -489,7 +495,7 @@ The ``Passenger`` model defines a ``BelongsToMany`` relationship with
489
495
490
496
The following sample code shows how to create a ``SpaceShip`` model in
491
497
a MySQL database and related ``Passenger`` models in a MongoDB database and
492
- the data created by running the code. Click the :guilabel:`View Output ` button
498
+ the data created by running the code. Click the :guilabel:`VIEW OUTPUT ` button
493
499
to see the data created by running the code:
494
500
495
501
.. io-code-block::
0 commit comments