-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
This ticket is intended to replace MONGOID-5382.
Background
- "mongoizing" means type casting from Ruby to the MongoDB database, e.g. when persisting data
- "demongoizing" means type casting from the MongoDB database to Ruby, e.g. when querying data
MONGOID-5221/MONGOID-5222cleaned up various cases of mongoizing/demongoizing for ambigous types. However, a brute force approach was taken where uncastable values (e.g. converting String "Foobar" to Integer) would simply convert as nil. This can lead to inadvertent data-loss.MONGOID-5408implemented a "Mongoid::RawValue" wrapper class intended to allow querying for raw values in the database.
Proposal
Instead of mongoizing/demongoizing ambiguous types to nil, we should:
- When mongoizing (persisting), raise an InvalidType error when attempting to assign an completely uncastable type, e.g. String "Foobar" to Integer. Note that String "123.456", etc. is still valid, as well as String "" which casts to nil.
- When demongoizing (querying), return uncastable values wrapped in Mongoid::RawValue. For example, if the DB contains "Foobar" on an integer "my_number" field, the model will get "my_number" returned as Mongoid::RawValue("Foobar").
Both new behaviors should be wrapped in a respective feature flags.