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

Touch relations on create caused regression for after_save callbacks

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

      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
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: