Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4779

Calculation is different by cache in memory for association document

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Done
    • 7.0.0, 7.0.5
    • None
    • Associations
    • 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.

       

       

      Attachments

        Activity

          People

            neil.shweky@mongodb.com Neil Shweky (Inactive)
            holygrail81@gmail.com Kuniaki Hori
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: