@@ -57,16 +57,17 @@ changed in Mongoid 8.0:
57
57
Please refer to :ref:`configuration option <configuration-options>` for
58
58
the description and effects of each of these options.
59
59
60
- Storing Uncastable Value
61
- ------------------------
60
+ Storing Uncastable Values
61
+ -------------------------
62
62
63
- In Mongoid 8, Mongoid standardizes the storing of "uncastable values." On
64
- attempting to write an uncastable value, a ``nil`` is written instead. See the
65
- secion on :ref:`Uncastable Values <uncastable-values>` for more details.
63
+ In Mongoid 8, Mongoid standardizes the storing and reading of "uncastable
64
+ values." On attempting to read or write an uncastable value, a ``nil`` is
65
+ returned or written instead. See the section on
66
+ :ref:`Uncastable Values <uncastable-values>` for more details.
66
67
67
- Some ``mongoize`` methods were also changed to perform consistently with rails
68
- and the other mongoize methods. The following is a table of the changes in
69
- functionality:
68
+ Some ``mongoize`` and ``demongoize`` methods were also changed to perform
69
+ consistently with rails and the other `` mongoize`` and ``demongoize`` methods.
70
+ The following is a table of the changes in functionality:
70
71
71
72
+--------------+------------------------+------------------------+-------------------+
72
73
| Field Type | Situation | Previous Functionality | New Functionality |
@@ -75,16 +76,48 @@ functionality:
75
76
| | string is assigned: | | |
76
77
| | "bogus value" | | |
77
78
+--------------+------------------------+------------------------+-------------------+
78
- | Array/Set | When a value that is | raise ``InvalidValue`` | return ``nil`` |
79
- | | not an array or set is | error | |
80
- | | assigned, and does NOT | | |
81
- | | respond to ``to_a``: 1 | | |
79
+ | Array/Hash | When a value that is | raise ``InvalidValue`` | return ``nil`` |
80
+ | | not an array or hash | error | |
81
+ | | is assigned | | |
82
+ +--------------+------------------------+------------------------+-------------------+
83
+ | Set | When a value that is | raise ``NoMethodError``| return ``nil`` |
84
+ | | not a set is assigned: | Exception: undefined | |
85
+ | | 1 | method ``to_a`` for | |
86
+ | | | 1:Integer | |
87
+ +--------------+------------------------+------------------------+-------------------+
88
+ | Regexp | When persisting and | return a | return a |
89
+ | | reading a Regexp from | ``BSON::Regexp::Raw`` | ``Regexp`` |
90
+ | | the database | | |
91
+ +--------------+------------------------+------------------------+-------------------+
92
+ | Time/DateTime| When assigning a | raise ``NoMethodError``| return ``nil`` |
93
+ | | bogus value: ``:bogus``| Exception: undefined | |
94
+ | | | method ``to_i`` | |
95
+ | | | for :bogus:Symbol | |
96
+ +--------------+------------------------+------------------------+-------------------+
97
+ | Time/DateTime| When demongoizing a | raise ``NoMethodError``| "bogus": |
98
+ | | non-Time value: | Exception: undefined | return ``nil`` |
99
+ | | "bogus", | method ``getlocal`` | |
100
+ | | ``Date.today`` | for "bogus":String | ``Date.today``: |
101
+ | | | | return a |
102
+ | | | | ``Time/DateTime`` |
103
+ +--------------+------------------------+------------------------+-------------------+
104
+ | Date | When assigning or | raise ``NoMethodError``| return ``nil`` |
105
+ | | demongoizing a bogus | Exception: undefined | |
106
+ | | value: :bogus | method ``year`` | |
107
+ | | | for :bogus:Symbol | |
82
108
+--------------+------------------------+------------------------+-------------------+
83
109
| All Other | When an uncastable | undefined behavior, | return ``nil`` |
84
- | Types | value is assigned | occasionally raises | |
110
+ | Types | value is assigned | occasionally raise | |
85
111
| | | ``NoMethodError`` | |
86
112
+--------------+------------------------+------------------------+-------------------+
87
113
114
+ .. note::
115
+
116
+ The ``demongoize`` methods on container objects (i.e. Hash, Array) have not
117
+ changed to prevent bugs when modifying and saving those objects. See
118
+ https://jira.mongodb.org/browse/MONGOID-2951 for a longer discussion on these
119
+ bugs.
120
+
88
121
89
122
Order of Callback Invocation
90
123
----------------------------
0 commit comments