提交 da8de911 编写于 作者: A Aaron Patterson

push add to transaction logic down to the instance

the transaction object shouldn't know so much about active record
objects, so let's push the conditionals in to the instance.
上级 e87ff501
......@@ -234,6 +234,10 @@ def add_transaction_record(record)
current_transaction.add_record(record)
end
def transaction_state
current_transaction.state
end
# Begins the transaction (and turns off auto-committing).
def begin_db_transaction() end
......
......@@ -55,11 +55,7 @@ def initialize(connection, options)
end
def add_record(record)
if record.has_transactional_callbacks?
records << record
else
record.set_transaction_state(@state)
end
records << record
end
def rollback
......
......@@ -318,7 +318,11 @@ def rolledback!(force_restore_state: false, should_run_callbacks: true) #:nodoc:
# Add the record to the current transaction so that the +after_rollback+ and +after_commit+ callbacks
# can be called.
def add_to_transaction
self.class.connection.add_transaction_record(self)
if has_transactional_callbacks?
self.class.connection.add_transaction_record(self)
else
set_transaction_state(self.class.connection.transaction_state)
end
remember_transaction_record_state
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册