ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 9.1.2
    • Affects Version/s: 9.1.0, 9.1.1
    • Component/s: Associations
    • None
    • None
    • Fully Compatible
    • Ruby Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Criteria#eager_load writes the preloaded documents into a field named after the association (for example device), and hydration keeps that field in the document's attributes. Any write of the whole document, such as upsert or reassigning an embedded collection, then saves that copy, overwriting any data already stored under that name. Because the getter for a referenced association reads a stored field with the association's name instead of querying, later loads keep returning the stale copy. A fix is proposed in https://github.com/mongodb/mongoid/pull/6202.

      class Device
        include Mongoid::Document
      end
      
      class Port
        include Mongoid::Document
        belongs_to :device
      end
      
      device = Device.create!
      port = Port.create!(device: device)
      
      Port.eager_load(:device).first.upsert
      
      Port.collection.find(_id: port.id).first
      # => { "_id" => ..., "device_id" => ..., "device" => [ { "_id" => ... } ] }
      

            Assignee:
            Dmitry Rybakov
            Reporter:
            Dmitry Rybakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: