@@ -519,15 +519,15 @@ method to remove all embedded ``Album`` documents from the ``Band`` class:
519519Association Behaviors
520520---------------------
521521
522- When working with associations in {+odm+}, there are various behaviors you can
523- use to customize how associations are handled in your application. The following
522+ When working with associations in {+odm+}, there are various behaviors that
523+ allow you to customize how associations are handled in your application. The following
524524sections describe common association behaviors.
525525
526526Extensions
527527~~~~~~~~~~
528528
529529Extensions allow you to add specific functionality to an association. You can
530- define an extension on an association by specifying a block to the association
530+ define an extension on an association by specifying a block in the association
531531definition, as shown in the following example:
532532
533533.. literalinclude:: /includes/data-modeling/association-behaviors.rb
@@ -556,7 +556,7 @@ Custom Keys
556556By default, {+odm+} uses the ``_id`` field of the parent class when looking up
557557associations. You can specify a different field to use by specifying the
558558``primary_key`` and ``foreign_key`` macros. The following example specifies a new
559- primary and foreign key for the ``Band `` and ``Album `` classes :
559+ primary and foreign key for the ``albums `` association on a ``Band `` class :
560560
561561.. literalinclude:: /includes/data-modeling/association-behaviors.rb
562562 :language: ruby
@@ -566,9 +566,9 @@ primary and foreign key for the ``Band`` and ``Album`` classes:
566566If you are specifying a ``has_and_belongs_to_many`` association, you can also
567567set the ``inverse_primary_key`` and ``inverse_foreign_key`` macros. The
568568``inverse_primary_key`` macro specifies the field on the local model that the
569- remote model uses to look up the local model documents, and
570- the ``inverse_foreign_key`` macro specifies the field on the remote model
571- storing the values in ``inverse_primary_key``.
569+ remote model uses to look up the documents.
570+ The ``inverse_foreign_key`` macro specifies the field on the remote model
571+ that stores the values found in ``inverse_primary_key``.
572572
573573The following example specifies a new primary and foreign key for the
574574``Band`` and ``Members`` classes in a ``has_and_belongs_to_many`` association:
@@ -577,6 +577,7 @@ The following example specifies a new primary and foreign key for the
577577 :language: ruby
578578 :start-after: # start-custom-inverse-keys
579579 :end-before: # end-custom-inverse-keys
580+ :emphasize-lines: 9, 20
580581
581582Custom Scopes
582583~~~~~~~~~~~~~
@@ -585,7 +586,7 @@ You can set a specific scope on an association by using the ``scope`` parameter.
585586The ``scope`` parameter determines which documents {+odm+} considers to be part
586587of an association. A scoped association returns only documents that match the
587588scope conditions when queried. You can set the ``scope`` to either a ``Proc`` with an arity
588- of zero, or a ``Symbol`` that references a named scope on the associated model.
589+ of zero or a ``Symbol`` that references a named scope on the associated model.
589590The following example sets custom scopes on associations in a ``Band`` class:
590591
591592.. literalinclude:: /includes/data-modeling/association-behaviors.rb
@@ -624,7 +625,7 @@ You can turn off this validation behavior by setting the ``validate`` macro to
624625Polymorphism
625626~~~~~~~~~~~~
626627
627- {+odm+} supports polymorphism on the child class in one-to-one and one-to-many associations.
628+ {+odm+} supports polymorphism on the child classes of one-to-one and one-to-many associations.
628629Polymorphic associations allows a single association to contain objects of different class
629630types. You can define a polymorphic association by setting the ``polymorphic``
630631option to ``true`` in a child association and adding the ``as`` option to the
@@ -674,8 +675,8 @@ only for looking up records. This allows you to refactor your
674675code without breaking the associations in your data.
675676
676677Polymorphic type aliases are global. The keys you specify must be unique across your
677- entire code base. However, it is possible to register alternative resolvers, which
678- may be used for different subsets of your models. In this case, the keys must
678+ entire code base. However, it is possible to register alternative resolvers that
679+ can be used for different subsets of your models. In this case, the keys must
679680only be unique for each resolver. The following example shows how to register
680681alternate resolvers:
681682
@@ -698,7 +699,7 @@ the following options:
698699 callbacks.
699700- ``destroy``: Deletes the child documents and runs all model callbacks.
700701- ``nullify``: Sets the foreign key of the child documents to ``nil``. The child
701- document might become orphaned if it is only referenced by the parent.
702+ document might become orphaned if it is referenced by only the parent.
702703- ``restrict_with_exception``: Raises an exception if the child document is not
703704 empty.
704705- ``restrict_with_error``: Cancels the operation and returns ``false`` if the
@@ -707,7 +708,7 @@ the following options:
707708If you don't specify any ``dependent`` options, {+odm+} leaves the child
708709document unchanged when the parent document is deleted. The child document
709710continues to reference the deleted parent document. If the child document is
710- only referenced through the parent, the child document becomes orphaned.
711+ referenced through only the parent, the child document becomes orphaned.
711712
712713The following example specifies ``dependent`` options on the ``Band`` class:
713714
@@ -719,13 +720,13 @@ The following example specifies ``dependent`` options on the ``Band`` class:
719720Autosave Referenced Associations
720721~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
721722
722- By default, {+odm+} does not automatically save associated documents for
723+ By default, {+odm+} does not automatically save associated documents from
723724non-embedded associations when saving the parent document. Because of this, it's
724725possible to create dangling references to documents that don't exist through
725726associations. You can use the ``autosave`` option on a referenced association to
726727automatically save associated documents when saving the parent document. The
727728following example creates a ``Band`` class with an associated ``Album`` class
728- and specifies the ``autosave`` option on the ``Album`` association :
729+ and specifies the ``autosave`` option:
729730
730731.. literalinclude:: /includes/data-modeling/association-behaviors.rb
731732 :language: ruby
@@ -782,7 +783,7 @@ following example instructs {+odm+} to touch the ``bands_updated_at`` field:
782783
783784 In embedded associations, when an embedded document is touched, {+odm+}
784785 touches its parents recursively. Because of this, adding a ``touch``
785- attribute to ``embedded_in`` association is unnecessary. {+odm+} does not
786+ attribute to an ``embedded_in`` association is unnecessary. {+odm+} does not
786787 support specifying additional fields to touch in ``embedded_in``
787788 associations.
788789
@@ -792,7 +793,7 @@ Counter Cache
792793You can use the ``counter_cache`` option to store the number of objects
793794that belong to an associated field. When specifying this option, {+odm+} stores
794795an extra attribute on the associated models to store the count. Because of this,
795- you must specify the ``Mongoid::Attributes::Dynamic`` module in associated
796+ you must specify the ``Mongoid::Attributes::Dynamic`` module in the associated
796797classes. The following example adds the ``counter_cache`` option to a ``Band``
797798class and specifies the ``Mongoid::Attributes::Dynamic`` in a ``Label`` class:
798799
@@ -818,7 +819,7 @@ document. The following example shows how to access metadata by using the
818819
819820.. note::
820821
821- Replace ``<association name >`` in the preceding example with the name of your
822+ Replace ``<association_name >`` in the preceding example with the name of your
822823 association.
823824
824825Attributes
@@ -828,7 +829,7 @@ All associations contain attributes that store information about the associated
828829document. Associations contain the following attributes:
829830
830831- ``_target``: Contains the proxied document or documents
831- - ``_base``: Contains the document that the association is defined on
832+ - ``_base``: Contains the document on which the association is defined
832833- ``_association``: Contains information about the association
833834
834835The following example accesses each of the preceding attributes:
0 commit comments