-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Associations
-
(copied to CRM)
Currently in Mongoid, there is a :touch option on the embedded_in association. This option defaults to false. Specifying touch: false (the default) in mongoid 8 and earlier has the following functionality:
- calling #touch on the child touches the parent
- updating the child does not update the updated_at of the parent
After MONGOID-5142, this changed to, for touch: false:
- calling #touch on the child does not touch the parent (different than 8.0 default)
- updating the child does not update the updated_at of the parent (same)
for touch: true:
- calling #touch on the child touches the parent (same as 8.0 default)
- updating the child updates the updated_at of the parent (different)
Now, after MONGOID-5142, the default behavior has changed whether or not we keep the :touch default as true or false. I think we should take this opportunity to change the default of the :touch option to true, as per the use cases below.
If we decide to keep touch: false as the default, we should add to the release notes that the default behavior of touch has changed.
Note that the default for referenced associations would stay the same (false)
Original Ticket
--------------
Currently in Mongoid, when an embedded document is saved, the parent is also saved. If an embedded document is touched, the parent therefore would also be touched. It is possible to specify touch:false on an embedded_in association but this has no effect. To provide diagnostics for this incorrect usage, Mongoid should prohibit specifying touch:false on an embedded_in association.
Additionally don't forget to update the docs here: https://docs.mongodb.com/mongoid/7.3/tutorials/mongoid-relations/index.html#touching
https://jira.mongodb.org/browse/MONGOID-5274 is filed as an improvement ticket to implement touch:false behavior for embedded associations.
- causes
-
MONGOID-5790 Informative error message if parent document is loaded after embedded
- Closed
- has to be done after
-
MONGOID-5142 Perform a single write for all touches
- Closed
- has to be done before
-
MONGOID-3252 Adding or removing a document to embeds_one/embeds_many does not change updated_at on parent
- Closed
- is duplicated by
-
MONGOID-5274 Implement touch: false for embedded documents, permitting saving of child without touching parent
- Closed
- is related to
-
MONGOID-5508 Test touch option on belongs_to
- Closed
- related to
-
MONGOID-3468 Always touch parents of embedded documents when embedded documents are touched
- Closed
-
MONGOID-5274 Implement touch: false for embedded documents, permitting saving of child without touching parent
- Closed