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

accepts_nested_attributes_for no longer sets autosave: true

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.2
    • Affects Version/s: 7.0.0
    • Component/s: None
    • None

      https://github.com/mongodb/mongoid/blob/master/lib/mongoid/attributes/nested.rb#L77

      def autosave_nested_attributes(association)
        if association.autosave?
          Association::Referenced::AutoSave.define_autosave!(association)
        end
      end

      This function is meant to set the association to autosave if it is not already set to  autosave. Instead it is setting it to autosave if it already is set to autosave (i.e does nothing). This causes failures like so:

      class A
        include Mongoid::Document
        has_many :bs
        accepts_nested_attributes_for :bs
      end
      class B
        include Mongoid::Document
        belongs_to :a
      end
      
      a = A.new
      a.bs.build
      a.save
      B.count # 0

            Assignee:
            sam.rossi@mongodb.com Samuel Rossi (Inactive)
            Reporter:
            tzar Tapio Saarinen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: