Skip to content

Commit 78f7284

Browse files
committed
MR PR fixes 1
1 parent acfb65b commit 78f7284

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

source/includes/interact-data/scoping.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Band
4848
field :name, type: String
4949
field :active, type: Boolean
5050

51-
default_scope ->{ where(active: true) }
51+
default_scope -> { where(active: true) }
5252
end
5353
# end-default-scope-1
5454

@@ -102,8 +102,12 @@ class Band
102102
label.bands.push(band)
103103
label.bands # Displays the Band because "active" is "true"
104104
band.update_attribute(:active, false) # Updates "active" to "false"
105-
label.bands # Still displays the Band
106-
label.reload.bands # Won't display the Band after reloading
105+
106+
# Displays the "Ghost Mountain" band
107+
label.bands # => {"_id":"...","name":"Ghost Mountain",...}
108+
109+
# Won't display "Ghost Mountain" band after reloading
110+
label.reload.bands # => nil
107111
# end-scope-association-steps
108112

109113
# start-scope-query-behavior

source/interact-data/scoping.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6668
You can define ``Proc`` objects and blocks in named scopes so that they
6769
accept 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,
7072
which matches documents in which the ``country`` field value
7173
is the specified value passed as a parameter:
7274

@@ -109,8 +111,11 @@ criteria to most queries. By defining a default scope, you specify these
109111
criteria as the default for any queries that use the model. Default
110112
scopes 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:
243248
Class 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
248253
the following example:
249254

250255
.. literalinclude:: /includes/interact-data/scoping.rb

0 commit comments

Comments
 (0)