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

IdentityMap : issue when previously using only

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.2
    • Affects Version/s: None
    • Component/s: None
    • None

      I just ran into a weird issue.

      I have to play with object, retrieving only their id upon some conditions to build a main request. And then I display the corresponding results.

      class Product
        has_and_belongs_to_many :components, inverse_of: nil
      end
      
      class Component
      end
      
      class Component::Memory < Component
        field :quantity, type: Integer
      end
      

      Let say I have a Product with a Component::Memory.

      I want to retrieve the ids of some Component::Memory (there are many other types of components) to use them to query for Products. Well. But in my views, later, I have to effectively retrieve the Component::Memory through the relation.

      And it seems that the Component::Memory are loaded into the IdentityMap by the only request and when accessing to one through a relation accessor in Product for example, it looks in the IdentityMap, found it, and use it. But it is incomplete because of the only that restrained the attributes retrieved.

      The evidence can be made in the console:

      [1] pry(main)> Component::Memory.all.only(:_id).entries
      => [#<Component::Memory _id: 5003d8c5f581f90113000001, _type: "Component::Memory", created_at: nil, updated_at: nil, quantity: nil, type: nil>,
       #<Component::Memory _id: 50052142f581f9db17000001, _type: "Component::Memory", created_at: nil, updated_at: nil, quantity: nil, type: nil>]
      [2] pry(main)> Product.first.components.last.quantity
      => nil
      

      whereas :

      [3] pry(main)> Component::Memory.all.entries
      => [#<Component::Memory _id: 5003d8c5f581f90113000001, _type: "Component::Memory", created_at: 2012-07-16 09:03:44 UTC, updated_at: 2012-07-16 09:03:44 UTC, quantity: 1024, type: :ddr2>,
       #<Component::Memory _id: 50052142f581f9db17000001, _type: "Component::Memory", created_at: 2012-07-17 08:24:52 UTC, updated_at: 2012-07-17 08:24:52 UTC, quantity: 2048, type: :ddr2>]
      

      When identity_map is set to false, it works as expected.

      mongoid (3.0.1) - moped (1.1.1) - origin (1.0.4)

            Assignee:
            durran Durran Jordan
            Reporter:
            maximeg Maxime Garcia
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: