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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Blocker - P1
    • Resolution: Fixed
    • 7.0.2
    • 7.1.0.rc0, 7.0.3
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: