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

Identity Map and Single Collection Inheritance

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

      When enabling Identity Map, I can use a finder on class C to retrieve documents of type B, see the example below. When turning off Identity Map it works as expected and find returns nil. I'm confused if this is a bug or expected behaviour, because I see the same issue in an app that uses MongoMapper.

      Tried Mongoid 3.0.1, 3.0.2, 3.1.0.

      Mongoid.identity_map_enabled = true
      
      class A
        include Mongoid::Document
        field :name
      end
      
      class B < A
      end
      
      class C < A
      end
      
      3.times {
        A.create(:name => 'abcde')
        B.create(:name => 'abcde')
        C.create(:name => 'abcde')
      }
      # => 3 
      
      B.all.entries
      # => [#<B _id: 50150a2d662478c841000002, _type: "B", name: "abcde">, #<B _id: 50150a2d662478c841000005, _type: "B", name: "abcde">, #<B _id: 50150a2d662478c841000008, _type: "B", name: "abcde">]
      
      C.find(B.first._id)
      # => <B _id: 50150a2d662478c841000002, _type: "B", name: "abcde">
      
      C.find('50150a2d662478c841000002')
      # => <B _id: 50150a2d662478c841000002, _type: "B", name: "abcde"> 
      
      
      A.delete_all
      Mongoid.identity_map_enabled = false
      
      3.times {
        A.create(:name => 'abcde')
        B.create(:name => 'abcde')
        C.create(:name => 'abcde')
      }
      # => 3 
      
      B.all.entries
      # => [#<B _id: 50150c17662478c84100000b, _type: "B", name: "abcde">, #<B _id: 50150c17662478c84100000e, _type: "B", name: "abcde">, #<B _id: 50150c17662478c841000011, _type: "B", name: "abcde">]
      
      C.find(B.first._id)
      # => nil
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            matthiassiegel matthiassiegel
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: