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

Touch relations on create caused regression for after_save callbacks

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      It seems if you have a model that creates a child in :after_create but relies on changed state in :after_save, it no longer works as of e1c4f0bc8d7bd3077147638099392054418ae03f.

      context "regression" do
          class TestOther
            include Mongoid::Document
            belongs_to :test_regression
          end
      
          class TestRegression
            include Mongoid::Document
      
            has_many :test_others
      
            field :a
            field :b
      
            after_create :create_other
            after_save :update_b
      
            def create_other
              test_others.create()
            end
      
            def update_b
              if a_changed? && b.nil?
                update_attributes(:b => "foo")
              end
            end
          end
      
          it "does not work" do
            t = TestRegression.create(:a => "Hi")
            t.reload().b.should == "foo"
          end
        end
      

            Assignee:
            arthurnn Arthur Nogueira Neves
            Reporter:
            jonhyman Jon Hyman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: