File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -116,3 +116,32 @@ from the ``_translations`` hash:
116
116
117
117
See the section on :ref:`Localize :present Field Option <present-fields>` for
118
118
more details on how these are used.
119
+
120
+
121
+ Added ``:to`` and ``:from`` options to ``attribute_changed?``
122
+ -------------------------------------------------------------
123
+
124
+ Mongoid 8.1 adds the ``:to`` and ``:from`` options on the ``attribute_changed?``
125
+ method. These options can be used to inquire whether the attribute has been changed
126
+ to or from a certain value:
127
+
128
+ .. code:
129
+
130
+ class Person
131
+ include Mongoid::Document
132
+ field :name, type: String
133
+ end
134
+
135
+ person = Person.create!(name: "Trout")
136
+ person.name = "Ohtani"
137
+
138
+ person.name_changed?
139
+ # => true
140
+ person.name_changed?(from: "Trout")
141
+ # => true
142
+ person.name_changed?(to: "Ohtani")
143
+ # => true
144
+ person.name_changed?(from: "Trout", to: "Ohtani")
145
+ # => true
146
+ person.name_changed?(from: "Trout", to: "Fletcher")
147
+ # => false
You can’t perform that action at this time.
0 commit comments