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

Can't clone documents with embeds_many and store_as on 7.0.x

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 7.1.0.rc0, 7.0.3
    • Affects Version/s: 7.0.2
    • Component/s: None

      This code now errors out on the 7.0.x Mongoid version. I ran this code on 6.4.2, where it works, but it errors out on 7.0.0, 7.0.1, and 7.0.2.

      class TestModel
        include Mongoid::Document  embeds_many :other_models, :class_name => "OtherModel", :store_as => "x"
      end
      
      class OtherModel
        include Mongoid::Document
        embedded_in :test_model
      end
      
      m = TestModel.create
      m.other_models.create
      m.dup() 

      It errors with
      NoMethodError: undefined method `each_with_index' for nil:NilClass
      from /Users/jon/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/mongoid-7.0.0/lib/mongoid/copyable.rb:76:in `block in process_localized_attributes'

      because the code at https://github.com/mongodb/mongoid/blob/master/lib/mongoid/copyable.rb#L77 errors because it does not use the "store_as" value to find the attribute.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            jonhyman Jon Hyman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: