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

two embeded fields of same type treated as one

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

      I am still experiencing a problem with embedded fields of the same polymorphic type. In the example below only 'i_am_a' is written to. The values of 'i_love_to' is incorrectly added to 'i_am_a'.

      In addition to the minimal example below I have created a github repository with a rails program that embeds the example in case you want to try it out:
      git@github.com:digitalplaywright/bug.git

      Please let me know if you are able to reproduce it.

      This is a minimal example of the problem (as shown in the git repository above):

      class TagInteraction
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :name, :type => String
        field :random_num_id, :type => String
        field :status, :type => Symbol
      
        embedded_in :tag_interactable, :polymorphic => true
      end
      
      class Profile
        include Mongoid::Document
      
        embeds_many :i_am_a,    :class_name => 'TagInteraction', :as => :tag_interactable
        embeds_many :i_love_to, :class_name => 'TagInteraction', :as => :tag_interactable
      
        def find_bug
           self.i_am_a    << TagInteraction.new(random_num_id: 'test_id', name: 'person', status: :add)
           self.i_love_to << TagInteraction.new(random_num_id: 'test_id', name: 'dance', status: :add)
      
           save
           reload
      
        end
      end
      
      = Profile.create
      
      = p = Profile.first
      = p.find_bug
      
      = p.i_am_a
      => [#<TagInteraction _id: 4e840c81b6619e7e34000012, _type: nil, created_at: 2011-09-29 06:13:21 UTC, updated_at: 2011-09-29 06:13:21 UTC, name: "person", random_num_id: "test_id", status: :add>, #<TagInteraction _id: 4e840c81b6619e7e34000013, _type: nil, created_at: 2011-09-29 06:13:21 UTC, updated_at: 2011-09-29 06:13:21 UTC, name: "dance", random_num_id: "test_id", status: :add>]
      
      = p.i_love_to
      => []
      

      Mongoid outputs this on the shell:

      MONGODB mongo_development['profiles'].find({}).sort([[:_id, :asc]])
      MONGODB mongo_development['profiles'].update({"_id"=>BSON::ObjectId('4e840cb4b6619e7e34000014')}, {"$pushAll"=>{"i_am_a"=>[{"random_num_id"=>"test_id", "name"=>"person", "status"=>:add, "_id"=>BSON::ObjectId('4e840cb4b6619e7e34000015'), "updated_at"=>2011-09-29 06:14:12 UTC, "created_at"=>2011-09-29 06:14:12 UTC}]}})
      MONGODB mongo_development['profiles'].update({"_id"=>BSON::ObjectId('4e840cb4b6619e7e34000014')}, {"$pushAll"=>{"i_am_a"=>[{"random_num_id"=>"test_id", "name"=>"dance", "status"=>:add, "_id"=>BSON::ObjectId('4e840cb4b6619e7e34000016'), "updated_at"=>2011-09-29 06:14:12 UTC, "created_at"=>2011-09-29 06:14:12 UTC}]}})
      

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

              Created:
              Updated:
              Resolved: