Skip to content

Commit 9632227

Browse files
authored
MONGOID-5291 Clarify whether :touch option is applicable for all updates (#5481)
1 parent 7b42a4b commit 9632227

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

source/reference/associations.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,19 +1396,21 @@ Mongoid to instantiate a new document when the association is accessed and it is
13961396

13971397
Touching
13981398
--------
1399-
14001399
Any ``belongs_to`` association can take an optional ``:touch`` option which
1401-
will cause the parent document be touched whenever the child document is
1402-
touched:
1400+
will cause the parent document to be touched whenever the child document is
1401+
updated:
14031402

14041403
.. code-block:: ruby
14051404

14061405
class Band
14071406
include Mongoid::Document
1407+
field :name
14081408
belongs_to :label, touch: true
14091409
end
14101410

14111411
band = Band.first
1412+
band.name = "The Rolling Stones"
1413+
band.save! # Calls touch on the parent label.
14121414
band.touch # Calls touch on the parent label.
14131415

14141416
``:touch`` can also take a string or symbol argument specifying a field to

0 commit comments

Comments
 (0)