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

In Mongoid 7.0.1 clone, dup method is not working with embeds_many -> embeds_many relations

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0.rc0, 7.0.2, 7.0.3
    • Affects Version/s: 7.0.1
    • Component/s: Associations
    • Environment:
      We use rails 5.2.1 and just updated mongoid gem version to 7.0.1

      After update to mongoid 7.0.1, `dup` method started to raise an error`

      NoMethodError:
             undefined method `buildings' for #<Quote:0x00007fc276d0d1e0>
             Did you mean?  _building
                            _building?
                            binding
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:77:in `block (2 levels) in process_localized_attributes'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:76:in `each'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:76:in `each_with_index'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:76:in `block in process_localized_attributes'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:72:in `each'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:72:in `process_localized_attributes'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:77:in `block (2 levels) in process_localized_attributes'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:76:in `each'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:76:in `each_with_index'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:76:in `block in process_localized_attributes'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:72:in `each'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:72:in `process_localized_attributes'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:51:in `clone_document'
           # .../gems/mongoid-7.0.1/lib/mongoid/copyable.rb:22:in `clone'

      We have the following models relation in our project:

       

      class A
        include Mongoid::Document
      
        embeds_many :locations
      end
      
      class Location
        include Mongoid::Document
      
        embeds_many :buildings
      end
      
      class Building
        include Mongoid::Document
      end
      
      location = Location.create!
      location.buildings << Building.create!
      
      a = A.create!
      a.locations << location
      a.dup
      

       

      So when we call dup on top level class A object the error above is raised

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            dzmitry.kremez Dzmitry Kremez
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: