Module: AfterCommit::ConnectionAdapters

Defined in:
lib/after_commit.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/after_commit.rb', line 51

def self.included(base)
  base.class_eval do
    # The commit_db_transaction method gets called when the outermost
    # transaction finishes and everything inside commits. We want to
    # override it so that after this happens, any records that were saved
    # or destroyed within this transaction now get their after_commit
    # callback fired.
    def commit_db_transaction_with_callback
      commit_db_transaction_without_callback
      AfterCommit.trigger
    end
    alias_method_chain :commit_db_transaction, :callback
    
    def rollback_db_transaction_with_callback
      rollback_db_transaction_without_callback
      AfterCommit.clear
    end
    alias_method_chain :rollback_db_transaction, :callback
  end
end