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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 7.0.1
    • 7.1.0.rc0, 7.0.2, 7.0.3
    • Associations
    • We use rails 5.2.1 and just updated mongoid gem version to 7.0.1

    Description

      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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: