Details
-
Bug
-
Status: Closed
-
Major - P3
-
Resolution: Done
-
7.0.0, 7.0.5
-
None
-
None
-
MongoDB 3.4.20
Ruby on Rails 5.1.7
Description
I have a problem after updating Mongoid version from 6.4.4 to 7.0.0
I have encountered a case where the result of a calculation does not match with the sum of the fields of the associated document.
example:
class User |
include Mongoid::Document
|
include Mongoid::Timestamps
|
|
embeds_many :orders
|
end
|
|
class Order |
include Mongoid::Document
|
|
field :amount, type: Integer
|
|
embedded_in :user
|
end
|
when Mongoid 6.4.4
user.orders.build(amount: 200) |
user.orders.sum(:amount)
|
=> 200 |
|
user.orders.delete_all
|
|
user.orders.build(amount: 500) |
user.orders.sum(:amount)
|
=> 500 |
when Mongoid 7.0.0 ( also 7.0.5 )
user.orders.build(amount: 200) |
user.orders.sum(:amount)
|
=> 200 |
|
user.orders.delete_all
|
|
user.orders.build(amount: 500) |
user.orders.sum(:amount)
|
=> 200 |
Whether it was an intentional change or a bug could not be determined from the change log.
However, it feels like a very big change, so I want the same behavior as the previous version if possible.