You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MONGOID-5228 disallow _id to be updated on persisted documents (#5542)
* MONGOID-5228 - disallow _id to be updated on persisted documents
Previously, updating _id on any document (top-level or embedded) would silently ignore the _id attribute, making it appear as though the operation succeeded. This was misleading, since the _id didn't actually change. This change makes it so that _id is explicitly made immutable once a document has been persisted. The same behavior is intentionally enforced regardless of whether the document is embedded or not. If you find yourself needing to update the _id field in an embedded document, you'll need to use the lower-level driver methods to accomplish this. We believe modifying the _id field (even in embedded documents) is an anti-pattern.
* use a specialized error for immutability violations
* add a feature flag
* change the flag name, and account for existing nested attribute behavior
* wrong default for <9.0
* clean up a test that was unnecessarily sensitive to the _id changing
* another test that was unnecessarily sensitive to _id changes
* more tests that are too sensitive to _id changes
* we need to allow _id mutations if the _id was previously nil
* mention enforcement of _id immutability in the release notes
Copy file name to clipboardExpand all lines: lib/mongoid/warnings.rb
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -25,5 +25,6 @@ def warning(id, message)
25
25
warning:as_json_compact_deprecated,'#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.'
26
26
warning:symbol_type_deprecated,'The BSON Symbol type is deprecated by MongoDB. Please use String or StringifiedSymbol field types instead of the Symbol field type.'
27
27
warning:legacy_readonly,'The readonly! method will only mark the document readonly when the legacy_readonly feature flag is switched off.'
28
+
warning:mutable_ids,'Ignoring updates to immutable attribute `_id`. Please set Mongoid::Config.immutable_ids to true and update your code so that `_id` is never updated.'
0 commit comments