@@ -84,59 +84,69 @@ evolve an uncastable value, the inputted value is returned. See the section on
8484
8585Some ``mongoize``, ``demongoize`` and ``evolve`` methods were also changed to
8686perform consistently with rails and the other ``mongoize``, ``demongoize`` and
87- ``evolve`` methods. The following is a table of the changes in functionality:
88-
89- +--------------+------------------------+------------------------+-----------------------+
90- | Field Type | Situation | Previous Functionality | New Functionality |
91- +==============+========================+========================+=======================+
92- | Boolean | When a non-boolean | return ``false`` | return ``nil`` |
93- | | string is assigned: | | |
94- | | "bogus value" | | |
95- +--------------+------------------------+------------------------+-----------------------+
96- | Array/Hash | When a value that is | raise ``InvalidValue`` | return ``nil`` |
97- | | not an array or hash | error | |
98- | | is assigned | | |
99- +--------------+------------------------+------------------------+-----------------------+
100- | Set | When a value that is | raise ``NoMethodError``| return ``nil`` |
101- | | not a set is assigned: | Exception: undefined | |
102- | | 1 | method ``to_a`` for | |
103- | | | 1:Integer | |
104- +--------------+------------------------+------------------------+-----------------------+
105- | Regexp | When persisting and | return a | return a |
106- | | reading a Regexp from | ``BSON::Regexp::Raw`` | ``Regexp`` |
107- | | the database | | |
108- +--------------+------------------------+------------------------+-----------------------+
109- | Time/DateTime| When assigning a | raise ``NoMethodError``| return ``nil`` |
110- | | bogus value: ``:bogus``| Exception: undefined | |
111- | | | method ``to_i`` | |
112- | | | for :bogus:Symbol | |
113- +--------------+------------------------+------------------------+-----------------------+
114- | Time/DateTime| When demongoizing a | raise ``NoMethodError``| "bogus": |
115- | | non-Time value: | Exception: undefined | return ``nil`` |
116- | | "bogus", | method ``getlocal`` | |
117- | | ``Date.today`` | for "bogus":String | ``Date.today``: |
118- | | | | return a |
119- | | | | ``Time/DateTime`` |
120- +--------------+------------------------+------------------------+-----------------------+
121- | Date | When assigning or | raise ``NoMethodError``| return ``nil`` |
122- | | demongoizing a bogus | Exception: undefined | |
123- | | value: :bogus | method ``year`` | |
124- | | | for :bogus:Symbol | |
125- +--------------+------------------------+------------------------+-----------------------+
126- | Time/DateTime| When demongoizing a | raise ``NoMethodError``| return a |
127- | /Date | valid string: | Exception: undefined | ``Time/DateTime/Date``|
128- | | "2022-07-14 14:45:51 | method ``getlocal`` | |
129- | | -0400" | for "2022-07-14 | |
130- | | | 14:45:51 -0400":String | |
131- +--------------+------------------------+------------------------+-----------------------+
132- | All Types | When an uncastable | undefined behavior, | return ``nil`` |
133- | | value is assigned or | occasionally raise | |
134- | | demongoized | ``NoMethodError`` | |
135- +--------------+------------------------+------------------------+-----------------------+
136- | All Types | When an uncastable | undefined behavior, | return inputted value |
137- | | value is evolved | occasionally raise | |
138- | | | ``NoMethodError`` | |
139- +--------------+------------------------+------------------------+-----------------------+
87+ ``evolve`` methods. The following table shows the changes in functionality:
88+
89+ .. list-table::
90+ :widths: 1 2 2 2
91+ :stub-columns: 1
92+ :header-rows: 1
93+
94+ * - Field Type
95+ - Situation
96+ - Previous Functionality
97+ - New Functionality
98+
99+ * - | Boolean
100+ - | When a non-boolean string is assigned: "bogus value"
101+ - | return ``false``
102+ - | return ``nil``
103+
104+ * - Array/Hash
105+ - When a value that is not an array or hash is assigned
106+ - raise ``InvalidValue`` error
107+ - return ``nil``
108+
109+ * - | Set
110+ - | When a value that is not a set is assigned: 1
111+ - | raise ``NoMethodError`` Exception: undefined method ``to_a`` for 1:Integer
112+ - | return ``nil``
113+
114+ * - Regexp
115+ - When persisting and reading a Regexp from the database
116+ - return a ``BSON::Regexp::Raw``
117+ - return a ``Regexp``
118+
119+ * - | Time/DateTime
120+ - | When assigning a bogus value: ``:bogus``
121+ - | raise ``NoMethodError`` Exception: undefined method ``to_i`` for :bogus:Symbol
122+ - | return ``nil``
123+
124+ * - Time/DateTime
125+ - When demongoizing a non-Time value: "bogus", ``Date.today``
126+ - raise ``NoMethodError`` Exception: undefined method ``getlocal`` for "bogus":String
127+ - "bogus": return ``nil``
128+
129+ ``Date.today``: return ``Time/DateTime``
130+
131+ * - | Date
132+ - | When assigning or demongoizing a bogus value: :bogus
133+ - | raise ``NoMethodError`` Exception: undefined method ``year`` for :bogus:Symbol
134+ - | return ``nil``
135+
136+ * - Time/DateTime/Date
137+ - When demongoizing a valid string: "2022-07-14 14:45:51 -0400"
138+ - raise ``NoMethodError`` Exception: undefined method ``getlocal`` for "2022-07-14 14:45:51 -0400":String
139+ - return a ``Time/DateTime/Date``
140+
141+ * - | All Types
142+ - | When an uncastable value is assigned or demongoized
143+ - | undefined behavior, occasionally raise ``NoMethodError``
144+ - | return ``nil``
145+
146+ * - All Types
147+ - When an uncastable value is evolved
148+ - undefined behavior, occasionally raise ``NoMethodError``
149+ - return inputted value
140150
141151.. note::
142152
@@ -145,7 +155,6 @@ perform consistently with rails and the other ``mongoize``, ``demongoize`` and
145155 https://jira.mongodb.org/browse/MONGOID-2951 for a longer discussion on these
146156 bugs.
147157
148-
149158Changes to the ``attributes_before_type_cast`` Hash
150159---------------------------------------------------
151160
@@ -177,98 +186,144 @@ invocation for documents with associations.
177186
178187Referenced associations (``has_one`` and ``has_many``):
179188
180- +---------------------------------------+---------------------------------------+
181- | Mongoid 8.0 | Mongoid 7 |
182- +=======================================+=======================================+
183- | Parent :before_save | Parent :before_save |
184- +---------------------------------------+---------------------------------------+
185- | Parent :around_save_open | Parent :around_save_open |
186- +---------------------------------------+---------------------------------------+
187- | Parent :before_create | Parent :before_create |
188- +---------------------------------------+---------------------------------------+
189- | Parent :around_create_open | Parent :around_create_open |
190- +---------------------------------------+---------------------------------------+
191- | **Parent persisted in MongoDB** | **Parent persisted in MongoDB** |
192- +---------------------------------------+---------------------------------------+
193- | Child :before_save | Parent :around_create_close |
194- +---------------------------------------+---------------------------------------+
195- | Child :around_save_open | Parent :after_create |
196- +---------------------------------------+---------------------------------------+
197- | Child :before_create | Child :before_save |
198- +---------------------------------------+---------------------------------------+
199- | Child :around_create_open | Child :around_save_open |
200- +---------------------------------------+---------------------------------------+
201- | | Child :before_create |
202- +---------------------------------------+---------------------------------------+
203- | | Child :around_create_open |
204- +---------------------------------------+---------------------------------------+
205- | **Child persisted in MongoDB** | **Child persisted in MongoDB** |
206- +---------------------------------------+---------------------------------------+
207- | Child :around_create_close | Child :around_create_close |
208- +---------------------------------------+---------------------------------------+
209- | Child :after_create | Child :after_create |
210- +---------------------------------------+---------------------------------------+
211- | Child :around_save_close | Child :around_save_close |
212- +---------------------------------------+---------------------------------------+
213- | Child :after_save | Child :after_save |
214- +---------------------------------------+---------------------------------------+
215- | Parent :around_create_close | Parent :around_save_close |
216- +---------------------------------------+---------------------------------------+
217- | Parent :after_create | Parent :after_save |
218- +---------------------------------------+---------------------------------------+
219- | Parent :around_save_close | |
220- +---------------------------------------+---------------------------------------+
221- | Parent :after_save | |
222- +---------------------------------------+---------------------------------------+
189+ .. list-table::
190+ :header-rows: 1
191+ :widths: 50 50
192+
193+ * - Mongoid 8.0
194+ - Mongoid 7
195+
196+ * - | Parent :before_save
197+ - | Parent :before_save
198+
199+ * - Parent :around_save_open
200+ - Parent :around_save_open
201+
202+ * - | Parent :before_create
203+ - | Parent :before_create
204+
205+ * - Parent :around_create_open
206+ - Parent :around_create_open
207+
208+ * - | **Parent persisted in MongoDB**
209+ - | **Parent persisted in MongoDB**
210+
211+ * - Child :before_save
212+ - Parent :around_create_close
213+
214+ * - | Child :around_save_open
215+ - | Parent :after_create
216+
217+ * - Child :before_create
218+ - Child :before_save
219+
220+ * - | Child :around_create_open
221+ - | Child :around_save_open
222+
223+ * -
224+ - Child :before_create
225+
226+ * - |
227+ - | Child :around_create_open
228+
229+ * - **Child persisted in MongoDB**
230+ - **Child persisted in MongoDB**
231+
232+ * - | Child :around_create_close
233+ - | Child :around_create_close
234+
235+ * - Child :after_create
236+ - Child :after_create
237+
238+ * - | Child :around_save_close
239+ - | Child :around_save_close
240+
241+ * - Child :after_save
242+ - Child :after_save
243+
244+ * - | Parent :around_create_close
245+ - | Parent :around_save_close
246+
247+ * - Parent :after_create
248+ - Parent :after_save
249+
250+ * - | Parent :around_save_close
251+ - |
252+
253+ * - Parent :after_save
254+ -
223255
224256Embedded associations (``embeds_one`` and ``embeds_many``):
225257
226- +---------------------------------------+---------------------------------------+
227- | Mongoid 8.0 | Mongoid 7 |
228- +=======================================+=======================================+
229- | Parent :before_save | Child :before_save |
230- +---------------------------------------+---------------------------------------+
231- | Parent :around_save_open | Child :around_save_open |
232- +---------------------------------------+---------------------------------------+
233- | Parent :before_create | Child :around_save_close |
234- +---------------------------------------+---------------------------------------+
235- | Parent :around_create_open | Child :after_save |
236- +---------------------------------------+---------------------------------------+
237- | Child :before_save | Parent :before_save |
238- +---------------------------------------+---------------------------------------+
239- | Child :around_save_open | Parent :around_save_open |
240- +---------------------------------------+---------------------------------------+
241- | Child :before_create | Child :before_create |
242- +---------------------------------------+---------------------------------------+
243- | Child :around_create_open | Child :around_create_open |
244- +---------------------------------------+---------------------------------------+
245- | | Child :around_create_close |
246- +---------------------------------------+---------------------------------------+
247- | | Child :after_create |
248- +---------------------------------------+---------------------------------------+
249- | | Parent :before_create |
250- +---------------------------------------+---------------------------------------+
251- | | Parent :around_create_open |
252- +---------------------------------------+---------------------------------------+
253- | **Document persisted in MongoDB** | **Document persisted in MongoDB** |
254- +---------------------------------------+---------------------------------------+
255- | Child :around_create_close | |
256- +---------------------------------------+---------------------------------------+
257- | Child :after_create | |
258- +---------------------------------------+---------------------------------------+
259- | Child :around_save_close | |
260- +---------------------------------------+---------------------------------------+
261- | Child :after_save | |
262- +---------------------------------------+---------------------------------------+
263- | Parent :around_create_close | Parent :around_create_close |
264- +---------------------------------------+---------------------------------------+
265- | Parent :after_create | Parent :after_create |
266- +---------------------------------------+---------------------------------------+
267- | Parent :around_save_close | Parent :around_save_close |
268- +---------------------------------------+---------------------------------------+
269- | Parent :after_save | Parent :after_save |
270- +---------------------------------------+---------------------------------------+
258+ .. list-table::
259+ :header-rows: 1
260+ :widths: 50 50
261+
262+ * - Mongoid 8.0
263+ - Mongoid 7
264+
265+ * - | Parent :before_save
266+ - | Child :before_save
267+
268+ * - Parent :around_save_open
269+ - Child :around_save_open
270+
271+ * - | Parent :before_create
272+ - | Child :around_save_close
273+
274+ * - Parent :around_create_open
275+ - Child :after_save
276+
277+ * - | Child :before_save
278+ - | Parent :before_save
279+
280+ * - Child :around_save_open
281+ - Parent :around_save_open
282+
283+ * - | Child :before_create
284+ - | Child :before_create
285+
286+ * - Child :around_create_open
287+ - Child :around_create_open
288+
289+ * - |
290+ - | Child :around_create_close
291+
292+ * -
293+ - Child :after_create
294+
295+ * - |
296+ - | Parent :before_create
297+
298+ * -
299+ - Parent :around_create_open
300+
301+ * - | **Document persisted in MongoDB**
302+ - | **Document persisted in MongoDB**
303+
304+ * - Child :around_create_close
305+ -
306+
307+ * - | Child :after_create
308+ - |
309+
310+ * - Child :around_save_close
311+ -
312+
313+ * - | Child :after_save
314+ - |
315+
316+ * - Parent :around_create_close
317+ - Parent :around_create_close
318+
319+ * - | Parent :after_create
320+ - | Parent :after_create
321+
322+ * - Parent :around_save_close
323+ - Parent :around_save_close
271324
325+ * - | Parent :after_save
326+ - | Parent :after_save
272327
273328``Changeable`` Module Behavior Made Compatible With ``ActiveModel::Dirty``
274329--------------------------------------------------------------------------
0 commit comments