Skip to content

Commit c18f7e7

Browse files
authored
MONGOID-5232 Add Feature Flag: Bring Mongoid::Document's === implementation in alignment with Ruby behavior (#5142)
* MONGOID-5232 add feature flag * MONGOID-5232 add config tests * MONGOID-5232 add docs for feature flag * MONGOID-5232 add note to docs about global flag
1 parent 306fe4a commit c18f7e7

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

source/reference/configuration.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ for details on driver options.
296296
# existing method. (default: false)
297297
scope_overwrite_exception: false
298298

299+
# Corrects === behavior to be consistent with Ruby by only calling is_a?
300+
# (default: false)
301+
triple_equals_uses_is_a: false
302+
299303
# In Mongoid 7.3.3 and earlier, when setting an embedded document, setting
300304
# it to nil, and then setting it again to that same original value, the
301305
# second update would not work and the value for the embedded document

source/release-notes/mongoid-7.4.txt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,45 @@ side with the left hand side as the argument:
3535
.. code-block:: ruby
3636

3737
ModelClass === instance
38-
38+
3939
# equivalent to:
4040
instance.is_a?(ModelClass)
4141

4242
Previously, ``===`` returned ``true`` for some cases when the equivalent Ruby
4343
``===`` implementation returned false.
4444

45+
.. note::
46+
47+
In order to get this functionality, the ``Mongoid::triple_equals_uses_is_a``
48+
global flag must be set to true. If it is set to false, the ``===`` operator
49+
will function as it did in Mongoid 7.3.
50+
4551
Mongoid 7.4 behavior:
4652

4753
.. code-block:: ruby
4854

4955
class Band
5056
include Mongoid::Document
5157
end
52-
58+
5359
class CoverBand < Band
5460
end
55-
61+
5662
band = Band.new
5763
cover_band = CoverBand.new
58-
64+
5965
band === Band
6066
# => false
61-
67+
6268
cover_band === Band
6369
# => false
64-
70+
6571
Band === Band
6672
# => false
67-
73+
6874
CoverBand === Band
6975
# => false
70-
76+
7177
Mongoid 7.3 behavior:
7278

7379
.. code-block:: ruby
@@ -77,10 +83,10 @@ Mongoid 7.3 behavior:
7783

7884
cover_band === Band
7985
# => true
80-
86+
8187
Band === Band
8288
# => true
83-
89+
8490
CoverBand === Band
8591
# => true
8692

@@ -92,7 +98,7 @@ and matches the core Ruby behavior:
9298

9399
Band === band
94100
# => true
95-
101+
96102
Band === cover_band
97103
# => true
98104

@@ -132,11 +138,11 @@ documents, the aliases are now expanded. Given the following definitions:
132138
include Mongoid::Document
133139
embeds_many :managers
134140
end
135-
141+
136142
class Manager
137143
include Mongoid::Document
138144
embedded_in :band
139-
145+
140146
field :name, as: :n
141147
end
142148

0 commit comments

Comments
 (0)