Skip to content

Commit 479216a

Browse files
p-mongopneilshweky
authored
MONGOID-5243 update 7.4 release notes to state all changes are compatible, add missing changes (#5175)
* describe all changes as compatible, mention required options * document broken_aggregables * document broken_updates * document compare_time_by_ms * broken_and * broken_scoping * Update docs/release-notes/mongoid-7.4.txt Co-authored-by: Neil Shweky <[email protected]> * remove redundant to true * Update docs/release-notes/mongoid-7.4.txt Co-authored-by: Neil Shweky <[email protected]> * Update docs/release-notes/mongoid-7.4.txt Co-authored-by: Neil Shweky <[email protected]> * fix and example Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Neil Shweky <[email protected]>
1 parent 8a821e4 commit 479216a

File tree

1 file changed

+198
-30
lines changed

1 file changed

+198
-30
lines changed

docs/release-notes/mongoid-7.4.txt

Lines changed: 198 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ The complete list of releases is available `on GitHub
1717
please consult GitHub releases for detailed release notes and JIRA for
1818
the complete list of issues fixed in each release, including bug fixes.
1919

20+
All behavior changes in Mongoid 7.4 must be explicitly requested by changing
21+
the value of configuration options as detailed below. By default,
22+
Mongoid 7.4 behaves the same as Mongoid 7.3.
23+
2024

2125
Ruby Version Support
2226
--------------------
@@ -25,11 +29,12 @@ As of version 7.4, Mongoid supports Ruby 2.5+.
2529
Support for Ruby 2.4 and earlier has been dropped.
2630

2731

28-
``===`` Operator Matches Ruby Semantics
29-
---------------------------------------
32+
Change ``===`` Operator To Match Ruby Semantics
33+
-----------------------------------------------
3034

31-
**Breaking change:** In Mongoid 7.4, the ``===`` operator works the same way
32-
as it does in Ruby, and is equivalent to calling ``is_a?`` on the right hand
35+
In Mongoid 7.4, the ``===`` operator on ``Mongoid::Document`` classes and
36+
instances can be configured to behave the same way as it does in Ruby,
37+
and is equivalent to calling ``is_a?`` on the right hand
3338
side with the left hand side as the argument:
3439

3540
.. code-block:: ruby
@@ -39,14 +44,11 @@ side with the left hand side as the argument:
3944
# equivalent to:
4045
instance.is_a?(ModelClass)
4146

42-
Previously, ``===`` returned ``true`` for some cases when the equivalent Ruby
43-
``===`` implementation returned false.
44-
45-
.. note::
46-
47-
In order to get this functionality, the ``Mongoid.legacy_triple_equals``
48-
global flag must be set to false. If it is set to true, the ``===`` operator
49-
will function as it did in Mongoid 7.3.
47+
In order to get this functionality, the ``Mongoid.legacy_triple_equals``
48+
option must be set to false. If it is set to true, which is the default for
49+
Mongoid 7.4, the ``===`` operator will function as it did in Mongoid 7.3:
50+
``===`` returned ``true`` for some cases when the equivalent Ruby
51+
``===`` implementation returned false, as per the examples below.
5052

5153
Mongoid 7.4 behavior:
5254

@@ -102,24 +104,31 @@ and matches the core Ruby behavior:
102104
Band === cover_band
103105
# => true
104106

107+
.. note::
108+
109+
The value of ``Mongoid.legacy_triple_equals`` option will change to ``false``
110+
by default in Mongoid 8.0.
111+
105112

106-
``BSON::ObjectId#as_json`` Override Is Made Optional
107-
----------------------------------------------------
113+
Return Hexadecimal ``_id`` Value from ``BSON::ObjectId#as_json``
114+
----------------------------------------------------------------
108115

109-
Mongoid 7.3 and earlier provided a ``BSON::ObjectId#as_json``
110-
implementation that was identical to the one provided by ``bson-ruby``.
111-
Mongoid 7.4 adds an option to bypass its copy of this implementation,
112-
delegating to ``BSON::ObjectId#as_json``: ``Mongoid.object_id_as_json_oid``.
116+
Mongoid 7.4 permits configuring the ``BSON::ObjectId#as_json`` method
117+
to return the ``_id`` value as a hexadecimal string instead of the
118+
``{"$oid" => "..."}`` hash it has returned in Mongoid 7.3 and previous
119+
versions.
120+
121+
When ``Mongoid.object_id_as_json_oid`` is set to ``false``, Mongoid will
122+
delegate to ``bson-ruby`` implementation of ``BSON::ObjectId#as_json``.
123+
In ``bson-ruby`` 4 the ``BSON::ObjectId#as_json`` method will continue
124+
to return the hash ``{"$oid" => "..."}`` for backwards compatibility, but
125+
in ``bson-ruby`` 5 the ``BSON::ObjectId#as_json`` method will return only
126+
the hexadecimal ObjectId string.
113127

114128
When ``Mongoid.object_id_as_json_oid`` is set to ``true``, Mongoid will
115129
install an implementation of ``BSON::ObjectId#as_json`` which returns
116130
the hash ``{"$oid" => "..."}`` as it did in Mongoid 7.3 and earlier.
117131

118-
When ``Mongoid.object_id_as_json_oid`` is set to ``false``, Mongoid will
119-
delegate to ``bson-ruby`` implementation of ``BSON::ObjectId#as_json``, which
120-
in ``bson-ruby`` 4 continues to return the hash ``{"$oid" => "..."}`` but
121-
in ``bson-ruby`` 5 will return only the hexadecimal ObjectId string.
122-
123132
The behavior of ``as_json`` is summarized in the following table:
124133

125134
.. list-table::
@@ -147,11 +156,37 @@ Associations now support the ``:scope`` argument, yielding
147156
:ref:`scoped associations <association-scope>`.
148157

149158

150-
``distinct`` and ``pluck`` Respect Field Aliases In Embedded Documents
151-
----------------------------------------------------------------------
159+
Compare Times With Millisecond Precision When Embedded Matching
160+
---------------------------------------------------------------
161+
162+
Mongoid 7.4 with the ``Mongoid.compare_time_by_ms`` option set to ``true``
163+
will truncate the times to millisecond precision when comparing them while
164+
performing embedded matching.
165+
166+
Time objects in Ruby have nanosecond precision, whereas MongoDB server
167+
can only store times with millisecond precision. Set the
168+
``Mongoid.compare_time_by_ms`` option to ``true`` to truncate times to
169+
millisecond precision when performing queries on already loaded embedded
170+
associations (this is also called "embedded matching" and is done completely
171+
in Ruby), to obtain the same query results when performing time comparisons
172+
regardless of which documents are being queried. Setting this option to
173+
``false`` will produce different results for queries on embedded associations
174+
that are already loaded into memory vs queries on unloaded associations and
175+
top-level models.
176+
177+
The ``Mongoid.compare_time_by_ms`` option is set to ``false`` by default
178+
in Mongoid 7.4 for backwards compatibility. In Mongoid 8 the default value
179+
will change to ``true``.
180+
181+
182+
Respect Field Aliases In Embedded Documents When Using ``distinct`` And ``pluck``
183+
---------------------------------------------------------------------------------
152184

153185
When ``distinct`` and ``pluck`` are used with aliased fields in embedded
154-
documents, the aliases are now expanded. Given the following definitions:
186+
documents, the aliases can be expanded if the ``Mongoid.broken_alias_handling``
187+
option is set to ``false``. By default, for backwards compatibility, in
188+
Mongoid 7.4 this option is set to true, yielding Mongoid 7.3 and earlier
189+
behavior. Given the following definitions:
155190

156191
.. code-block:: ruby
157192

@@ -167,24 +202,30 @@ documents, the aliases are now expanded. Given the following definitions:
167202
field :name, as: :n
168203
end
169204

170-
Mongoid 7.4 behavior:
205+
Mongoid 7.4 behavior with ``Mongoid.broken_alias_handling`` set to ``false``:
171206

172207
.. code-block:: ruby
173208

174209
# Expands out to "managers.name" in the query:
175210
Band.distinct('managers.n')
176211
Band.pluck('managers.n')
177212

178-
Mongoid 7.3 behavior:
213+
Mongoid 7.3 and 7.4 with ``Mongoid.broken_alias_handling`` set to ``true`` behavior:
179214

180215
.. code-block:: ruby
181216

182217
# Sends "managers.n" without expanding the alias:
183218
Band.distinct('managers.n')
184219
Band.pluck('managers.n')
185220

186-
Note that the alias expansion for top-level fields has already been
187-
done by Mongoid 7.3.
221+
.. note::
222+
223+
The alias expansion for top-level fields has already been done by Mongoid 7.3.
224+
225+
.. note::
226+
227+
The value of ``Mongoid.broken_alias_handling`` option will change to ``false``
228+
by default in Mongoid 8.0.
188229

189230

190231
``count``, ``sum``, ``avg``, ``min``, ``max`` Ignore Sort If Not Limiting/Skipping
@@ -199,3 +240,130 @@ an index where it wouldn't before:
199240
.. code-block:: ruby
200241

201242
Band.desc(:name).count
243+
244+
245+
Return ``0`` When Aggregating Empty Result Sets
246+
-----------------------------------------------
247+
248+
Mongoid 7.4 with the ``Mongoid.broken_aggregables`` option set to ``false``
249+
will return ``0`` from the ``sum`` method over an empty result set, for example:
250+
251+
.. code-block:: ruby
252+
253+
Product.where(impossible_condition: true).sum(:price)
254+
# => 0
255+
256+
Mongoid 7.3 and Mongoid 7.4 with the ``Mongoid.broken_aggregables`` option
257+
set to ``true`` (the default) returns ``nil`` in this case.
258+
259+
.. note::
260+
261+
The value of ``Mongoid.broken_aggregables`` option will change to ``false``
262+
by default in Mongoid 8.0.
263+
264+
265+
Correct Update Behavior When Replacing Association
266+
--------------------------------------------------
267+
268+
Mongoid 7.4 with the ``Mongoid.broken_updates`` option set to ``false``
269+
will correctly persist an ``embeds_one`` association target that is set to nil
270+
and then to a non-nil value, for example:
271+
272+
.. code-block:: ruby
273+
274+
class Canvas
275+
include Mongoid::Document
276+
277+
embeds_one :palette
278+
end
279+
280+
canvas.palette = palette
281+
canvas.palette = nil
282+
canvas.palette = palette
283+
284+
In Mongoid 7.3 and earlier, and in 7.4 with the ``Mongoid.broken_aggregables``
285+
option set to ``true`` (the default), ``canvas.palette`` would be ``nil`` when
286+
we would expect it to be ``palette``.
287+
288+
.. note::
289+
290+
The value of ``Mongoid.broken_update`` option will change to ``false``
291+
by default in Mongoid 8.0.
292+
293+
294+
Correct Logical ``and`` Query Generation
295+
----------------------------------------
296+
297+
Mongoid 7.4 with the ``Mongoid.broken_and`` option set to ``false``
298+
will preserve existing conditions when using ``and`` to add new conditions
299+
to a query when the same operator is used on the same field multiple times.
300+
For example, in the following query:
301+
302+
.. code-block:: ruby
303+
304+
Band.where(id: 1).and({year: {'$in' => [2020]}}, {year: {'$in' => [2021]}}).where(id: 2)
305+
306+
Mongoid 7.4 with the ``Mongoid.broken_and`` option set to ``false`` will
307+
generate the following criteria:
308+
309+
.. code-block:: ruby
310+
311+
#<Mongoid::Criteria
312+
selector: {"_id"=>1, "year"=>{"$in"=>[2020]}, "$and"=>[{"year"=>{"$in"=>[2021]}}, {"_id"=>2}]}
313+
options: {}
314+
class: Band
315+
embedded: false>
316+
317+
In Mongoid 7.3 and earlier, and in 7.4 with the ``Mongoid.broken_and``
318+
option set to ``true`` (the default), the following criteria would be
319+
generated instead which omit the {"$in" => [2021]} condition:
320+
321+
.. code-block:: ruby
322+
323+
<Mongoid::Criteria
324+
selector: {"_id"=>1, "year"=>{"$in"=>[2020]}, "$and"=>[{"_id"=>2}]}
325+
options: {}
326+
class: Band
327+
embedded: false>
328+
329+
.. note::
330+
331+
The value of ``Mongoid.broken_and`` option will change to ``false``
332+
by default in Mongoid 8.0.
333+
334+
335+
Restore Parent Scope When Exiting ``with_scope`` Block
336+
------------------------------------------------------
337+
338+
Mongoid 7.4 with the ``Mongoid.broken_scoping`` option set to ``false``
339+
will restore the parent scope when exiting a ``with_scope`` block.
340+
For example:
341+
342+
.. code-block:: ruby
343+
344+
Band.with_scope(year: 2020) do
345+
Band.with_scope(active: true) do
346+
# ...
347+
end
348+
349+
# {year: 2020} condition is applied here
350+
end
351+
352+
In Mongoid 7.3 and earlier, and in 7.4 with the ``Mongoid.broken_scoping``
353+
option set to ``true`` (the default), once any ``with_scope`` block finishes,
354+
all scopes are cleared:
355+
356+
.. code-block:: ruby
357+
358+
Band.with_scope(year: 2020) do
359+
Band.with_scope(active: true) do
360+
# ...
361+
end
362+
363+
# No scope is applied here
364+
end
365+
366+
.. note::
367+
368+
The value of ``Mongoid.broken_scoping`` option will change to ``false``
369+
by default in Mongoid 8.0.

0 commit comments

Comments
 (0)