@@ -169,7 +169,7 @@ Mongoid 8.0 behavior:
169169
170170 Band.any_of({name: 'Rolling Stone'}, {founded: 1990}).
171171 any_of({members: 2}, {last_tour: 1995})
172- # =>
172+ # =>
173173 # #<Mongoid::Criteria
174174 # selector: {"$or"=>[{"name"=>"Rolling Stone"}, {"founded"=>1990}],
175175 # "$and"=>[{"$or"=>[{"members"=>2}, {"last_tour"=>1995}]}]}
@@ -178,7 +178,7 @@ Mongoid 8.0 behavior:
178178 # embedded: false>
179179
180180 Band.any_of({name: 'Rolling Stone'}, {founded: 1990}).any_of({members: 2})
181- # =>
181+ # =>
182182 # #<Mongoid::Criteria
183183 # selector: {"$or"=>[{"name"=>"Rolling Stone"}, {"founded"=>1990}], "members"=>2}
184184 # options: {}
@@ -191,7 +191,7 @@ Mongoid 7 behavior:
191191
192192 Band.any_of({name: 'Rolling Stone'}, {founded: 1990}).
193193 any_of({members: 2}, {last_tour: 1995})
194- # =>
194+ # =>
195195 # #<Mongoid::Criteria
196196 # selector: {"$or"=>[{"name"=>"Rolling Stone"}, {"founded"=>1990},
197197 # {"members"=>2}, {"last_tour"=>1995}]}
@@ -200,7 +200,7 @@ Mongoid 7 behavior:
200200 # embedded: false>
201201
202202 Band.any_of({name: 'Rolling Stone'}, {founded: 1990}).any_of({members: 2})
203- # =>
203+ # =>
204204 # #<Mongoid::Criteria
205205 # selector: {"$or"=>[{"name"=>"Rolling Stone"}, {"founded"=>1990}], "members"=>2}
206206 # options: {}
@@ -248,3 +248,31 @@ Mongoid 7 output:
248248
249249Notice that in 7 ``attribute_was(:age)`` returns the old attribute value,
250250while in 8.0 ``attribute_was(:age)`` returns the new value.
251+
252+ ``*_previously_was``, ``previously_new_record?``, and ``previously_persisted?`` helpers
253+ ---------------------------------------------------------------------------------------
254+
255+ Mongoid 8.0 introduces ActiveModel-compatible ``*_previously_was`` helpers,
256+ as well as ActiveRecord-compatible ``previously_new_record?`` and
257+ ``previously_persisted?`` helpers:
258+
259+ .. code-block:: ruby
260+
261+ class User
262+ include Mongoid::Document
263+
264+ field :name, type: String
265+ field :age, type: Integer
266+ end
267+
268+ user = User.create!(name: 'Sam', age: 18)
269+ user.previously_new_record? # => true
270+
271+ user.name = "Nick"
272+ user.save!
273+ user.name_previously_was # => "Sam"
274+ user.age_previously_was # => 18
275+ user.previously_new_record? # => false
276+
277+ user.destroy
278+ user.previously_persisted? # => true
0 commit comments