Skip to content

Commit c4961cb

Browse files
authored
MONGOID-4979 Add :touch option to model save method (#5397)
* MONGOID-4979 test set_created_at * MONGOID-4979 undo test * MONGOID-4979 add touch: false option * MONGOID-4979 use the timeless method instead * MONGOID-4979 add optimization and timeless tests * MONGOID-4979 fix docs * MONGOID-4979 add release note * MONGOID-4979 add crud docs
1 parent 6b5f5cc commit c4961cb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

source/reference/crud.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ operations with examples.
145145
the save.*
146146

147147
*Pass* ``validate: false`` *option to bypass validations.*
148+
149+
*Pass* ``touch: false`` *option to ignore the updates to the updated_at
150+
field. If the document being save has not been previously persisted,
151+
this option is ignored and the created_at and updated_at fields will be
152+
updated with the current time.*
148153
-
149154
.. code-block:: ruby
150155

@@ -154,6 +159,7 @@ operations with examples.
154159
)
155160
person.save
156161
person.save(validate: false)
162+
person.save(touch: false)
157163

158164
person.first_name = "Christian Johan"
159165
person.save

source/release-notes/mongoid-8.1.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,18 @@ with a bang (!) raise an error:
4242

4343
Band.none.first!
4444
# => raise Mongoid::Errors::DocumentNotFound
45+
46+
47+
Added ``:touch`` option to ``#save``
48+
------------------------------------
49+
50+
Support for the ``:touch`` option has been added to the ``#save`` and ``#save!``
51+
methods. When this option is false, the ``updated_at`` field on the saved
52+
document and all of it's embedded documents will not be updated with the
53+
current time. When this option is true or unset, the ``updated_at`` field will
54+
be updated with the current time.
55+
56+
If the document being saved is a new document (i.e. it has not yet been
57+
persisted to the database), then the ``:touch`` option will be ignored, and the
58+
``updated_at`` (and ``created_at``) fields will be updated with the current
59+
time.

0 commit comments

Comments
 (0)