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

Bug with identity_map_enabled and queries using without() and only().

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

      It seems like mongoid is storing incomplete objects inside the identity map, check examples below:

      Without identity_map_enabled

      $ rails console
      Loading development environment (Rails 3.1.1)
      ruby-1.9.2-p290 :001 > s = Show.without(:episodes).first
      => # < Show _id: 4ec30e7722bbec0007000000, ...>
      ruby-1.9.2-p290 :002 > s.episodes.size
      => 0
      ruby-1.9.2-p290 :003 > s = Show.find('4ec30e7722bbec0007000000')
      => # < Show _id: 4ec30e7722bbec0007000000, ...>
      ruby-1.9.2-p290 :004 > s.episodes.size
      => 33

      With identity_map_enabled: true

      $ rails console
      Loading development environment (Rails 3.1.1)
      ruby-1.9.2-p290 :003 > s = Show.without(:episodes).first
      => # < Show _id: 4ec30e7722bbec0007000000, ...>
      ruby-1.9.2-p290 :004 > s.episodes.size
      => 0
      ruby-1.9.2-p290 :005 > s = Show.find('4ec30e7722bbec0007000000')
      => # < Show _id: 4ec30e7722bbec0007000000, ...>
      ruby-1.9.2-p290 :006 > s.episodes.size
      => 0

      I'm not sure about what would be the correct behavior. IMO mongoid should either make a new query fetching the empty fields or never include incomplete objects inside the identity map.

            Assignee:
            durran Durran Jordan
            Reporter:
            cezarsa Cezar Sá Espinola
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: