@@ -23,6 +23,79 @@ Upgrading to Mongoid 7.3
23
23
24
24
The following sections describe significant changes in Mongoid 7.3.
25
25
26
+ ``::Boolean`` Removed
27
+ ---------------------
28
+
29
+ **Breaking change:** Mongoid 7.3 removes the global ``::Boolean`` class.
30
+
31
+ This change should have no impact on classes that simply use ``Boolean``
32
+ fields, as the ``Boolean`` class is aliased from ``Mongoid::Fields``
33
+ (which is included in ``Mongoid::Document``). The following field definition
34
+ continues to work in 7.3 as it did in 7.2:
35
+
36
+ .. code-block:: ruby
37
+
38
+ class User
39
+ include Mongoid::Document
40
+
41
+ field :verified, type: Boolean
42
+ end
43
+
44
+ However, code that is not executed in the context of a class including
45
+ ``Mongoid::Document`` may need to explicitly qualify ``Boolean`` references.
46
+ The following snippet fails with Mongoid 7.3 due to ``Boolean`` being
47
+ unqualified:
48
+
49
+ .. code-block:: ruby
50
+
51
+ class User
52
+ include Mongoid::Document
53
+ end
54
+
55
+ User.field :verified, type: Boolean
56
+
57
+ To fix it, use the fully-qualified ``Mongoid::Boolean`` class:
58
+
59
+ .. code-block:: ruby
60
+
61
+ User.field :verified, type: Mongoid::Boolean
62
+
63
+ Note that ``class_eval`` is executed in the scope of the caller, not in
64
+ the scope of the class being modified. Thus even when using ``class_eval``
65
+ it is necessary to fully qualify ``Mongoid::Boolean``:
66
+
67
+ .. code-block:: ruby
68
+
69
+ User.class_eval do
70
+ field :verified, type: Mongoid::Boolean
71
+ end
72
+
73
+ Additionally, in Mongoid 7.2 ``::Boolean`` and ``Mongoid::Boolean`` were
74
+ different classes. In Mongoid 7.3 there is only one class which is
75
+ ``Mongoid::Boolean``.
76
+
77
+ It is possible to restore the global ``::Boolean`` class by executing in
78
+ your application:
79
+
80
+ .. code-block:: ruby
81
+
82
+ Boolean = Mongoid::Boolean
83
+
84
+ Note that this aliases ``Mongoid::Boolean`` to ``::Boolean`` such that there
85
+ is still only a single Boolean class:
86
+
87
+ .. code-block:: ruby
88
+
89
+ # With Mongoid 7.3:
90
+ Boolean = Mongoid::Boolean
91
+ Boolean == Mongoid::Boolean
92
+ # => true
93
+
94
+ # With Mongoid 7.2:
95
+ Boolean == Mongoid::Boolean
96
+ # => false
97
+
98
+
26
99
Selector Key Stringification
27
100
----------------------------
28
101
0 commit comments