@@ -51,8 +51,10 @@ scopes:
5151 :dedent:
5252 :emphasize-lines: 7-8
5353
54- Then, you can query by using the named scopes, as shown in the following
55- code:
54+ Then, you can query by using the named scopes. The following query uses
55+ the named scopes to match documents in which value of the ``country``
56+ field is ``"Japan"`` and value of the ``genre`` field includes
57+ ``"rock"``:
5658
5759.. literalinclude:: /includes/interact-data/scoping.rb
5860 :start-after: start-query-named-scope
@@ -66,7 +68,7 @@ Advanced Scoping
6668You can define ``Proc`` objects and blocks in named scopes so that they
6769accept parameters and extend functionality.
6870
69- This example defines a ``Band`` model that includes ``based_in`` scope,
71+ This example defines a ``Band`` model that includes the ``based_in`` scope,
7072which matches documents in which the ``country`` field value
7173is the specified value passed as a parameter:
7274
@@ -109,8 +111,11 @@ criteria to most queries. By defining a default scope, you specify these
109111criteria as the default for any queries that use the model. Default
110112scopes return ``Criteria`` objects.
111113
112- The following code defines a default scope on the ``Band`` model to only
113- retrieve documents in which the ``active`` field value is ``true``:
114+ To create a default scope, you must define the ``default_scope()`` method
115+ on your model class.
116+
117+ The following code defines the ``default_scope()`` method on the ``Band``
118+ model to only retrieve documents in which the ``active`` field value is ``true``:
114119
115120.. literalinclude:: /includes/interact-data/scoping.rb
116121 :start-after: start-default-scope-1
@@ -243,8 +248,8 @@ scope as the default scope at runtime, as shown in the following code:
243248Class Methods
244249-------------
245250
246- {+odm+} treats class methods on models that return ``Criteria`` objects
247- as scopes. You can chain these class methods when querying , as shown in
251+ {+odm+} treats class methods that return ``Criteria`` objects
252+ as scopes. You can query by using these class methods, as shown in
248253the following example:
249254
250255.. literalinclude:: /includes/interact-data/scoping.rb
0 commit comments