Skip to content
This repository
Newer
Older
100644 382 lines (360 sloc) 16.074 kb
db045dbb »
2004-11-24 Initial
1 require 'thread'
2
3 module ActiveRecord
a2932784 »
2008-10-05 Merge docrails
4 # See ActiveRecord::Transactions::ClassMethods for documentation.
5 module Transactions
4e50a35f »
2009-05-28 Break up DependencyModule's dual function of providing a "depend_on" …
6 extend ActiveSupport::Concern
a2875bec »
2009-05-11 Use DependencyModule for included hooks in ActiveRecord
7
a677da20 »
2005-04-10 Added rollbacks of transactions if they're active as the dispatcher i…
8 class TransactionError < ActiveRecordError # :nodoc:
9 end
10
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
11 included do
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
12 define_callbacks :commit, :rollback, :terminator => "result == false", :scope => [:kind, :name]
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
13 end
e444439f »
2010-11-28 Partialy revert f1c13b0
14
64454412 »
2010-06-16 Adds title to the rest of the files in activerecord/lib
15 # = Active Record Transactions
16 #
a2932784 »
2008-10-05 Merge docrails
17 # Transactions are protective blocks where SQL statements are only permanent
18 # if they can all succeed as one atomic action. The classic example is a
19 # transfer between two accounts where you can only have a deposit if the
20 # withdrawal succeeded and vice versa. Transactions enforce the integrity of
21 # the database and guard the data against program errors or database
22 # break-downs. So basically you should use transaction blocks whenever you
23 # have a number of statements that must be executed together or not at all.
64454412 »
2010-06-16 Adds title to the rest of the files in activerecord/lib
24 #
25 # For example:
db045dbb »
2004-11-24 Initial
26 #
a2932784 »
2008-10-05 Merge docrails
27 # ActiveRecord::Base.transaction do
db045dbb »
2004-11-24 Initial
28 # david.withdrawal(100)
29 # mary.deposit(100)
30 # end
31 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
32 # This example will only take money from David and give it to Mary if neither
33 # +withdrawal+ nor +deposit+ raise an exception. Exceptions will force a
34 # ROLLBACK that returns the database to the state before the transaction
35 # began. Be aware, though, that the objects will _not_ have their instance
a2932784 »
2008-10-05 Merge docrails
36 # data returned to their pre-transactional state.
db045dbb »
2004-11-24 Initial
37 #
98dc5827 »
2008-05-25 Merge docrails.
38 # == Different Active Record classes in a single transaction
4f59aacb »
2007-11-06 Explain semantics of having several different AR instances in a trans…
39 #
98dc5827 »
2008-05-25 Merge docrails.
40 # Though the transaction class method is called on some Active Record class,
4f59aacb »
2007-11-06 Explain semantics of having several different AR instances in a trans…
41 # the objects within the transaction block need not all be instances of
a2932784 »
2008-10-05 Merge docrails
42 # that class. This is because transactions are per-database connection, not
43 # per-model.
44 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
45 # In this example a +balance+ record is transactionally saved even
46 # though +transaction+ is called on the +Account+ class:
4f59aacb »
2007-11-06 Explain semantics of having several different AR instances in a trans…
47 #
48 # Account.transaction do
96fa4a2f »
2007-11-06 Make transaction documentation example more realistic
49 # balance.save!
50 # account.save!
4f59aacb »
2007-11-06 Explain semantics of having several different AR instances in a trans…
51 # end
52 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
53 # The +transaction+ method is also available as a model instance method.
54 # For example, you can also do this:
a2932784 »
2008-10-05 Merge docrails
55 #
56 # balance.transaction do
57 # balance.save!
58 # account.save!
59 # end
60 #
db045dbb »
2004-11-24 Initial
61 # == Transactions are not distributed across database connections
62 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
63 # A transaction acts on a single database connection. If you have
db045dbb »
2004-11-24 Initial
64 # multiple class-specific databases, the transaction will not protect
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
65 # interaction among them. One workaround is to begin a transaction
db045dbb »
2004-11-24 Initial
66 # on each class whose models you alter:
67 #
68 # Student.transaction do
69 # Course.transaction do
70 # course.enroll(student)
71 # student.units += course.units
72 # end
73 # end
74 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
75 # This is a poor solution, but fully distributed transactions are beyond
db045dbb »
2004-11-24 Initial
76 # the scope of Active Record.
77 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
78 # == +save+ and +destroy+ are automatically wrapped in a transaction
db045dbb »
2004-11-24 Initial
79 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
80 # Both +save+ and +destroy+ come wrapped in a transaction that ensures
81 # that whatever you do in validations or callbacks will happen under its
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
82 # protected cover. So you can use validations to check for values that
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
83 # the transaction depends on or you can raise exceptions in the callbacks
84 # to rollback, including <tt>after_*</tt> callbacks.
85 #
86 # As a consequence changes to the database are not seen outside your connection
87 # until the operation is complete. For example, if you try to update the index
88 # of a search engine in +after_save+ the indexer won't see the updated record.
89 # The +after_commit+ callback is the only one that is triggered once the update
90 # is committed. See below.
db045dbb »
2004-11-24 Initial
91 #
6e754551 »
2008-07-28 Merge docrails changes
92 # == Exception handling and rolling back
db045dbb »
2004-11-24 Initial
93 #
a2932784 »
2008-10-05 Merge docrails
94 # Also have in mind that exceptions thrown within a transaction block will
95 # be propagated (after triggering the ROLLBACK), so you should be ready to
96 # catch those in your application code.
6e754551 »
2008-07-28 Merge docrails changes
97 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
98 # One exception is the <tt>ActiveRecord::Rollback</tt> exception, which will trigger
a2932784 »
2008-10-05 Merge docrails
99 # a ROLLBACK when raised, but not be re-raised by the transaction block.
100 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
101 # *Warning*: one should not catch <tt>ActiveRecord::StatementInvalid</tt> exceptions
102 # inside a transaction block. <tt>ActiveRecord::StatementInvalid</tt> exceptions indicate that an
a2932784 »
2008-10-05 Merge docrails
103 # error occurred at the database level, for example when a unique constraint
104 # is violated. On some database systems, such as PostgreSQL, database errors
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
105 # inside a transaction cause the entire transaction to become unusable
a2932784 »
2008-10-05 Merge docrails
106 # until it's restarted from the beginning. Here is an example which
107 # demonstrates the problem:
108 #
109 # # Suppose that we have a Number model with a unique column called 'i'.
110 # Number.transaction do
111 # Number.create(:i => 0)
112 # begin
113 # # This will raise a unique constraint error...
114 # Number.create(:i => 0)
115 # rescue ActiveRecord::StatementInvalid
116 # # ...which we ignore.
117 # end
da840d13 »
2009-06-02 Add after_commit and after_rollback callbacks to ActiveRecord that ar…
118 #
a2932784 »
2008-10-05 Merge docrails
119 # # On PostgreSQL, the transaction is now unusable. The following
120 # # statement will cause a PostgreSQL error, even though the unique
121 # # constraint is no longer violated:
122 # Number.create(:i => 1)
123 # # => "PGError: ERROR: current transaction is aborted, commands
124 # # ignored until end of transaction block"
125 # end
126 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
127 # One should restart the entire transaction if an
128 # <tt>ActiveRecord::StatementInvalid</tt> occurred.
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
129 #
130 # == Nested transactions
131 #
6433c939 »
2010-05-02 edit pass in the transactions preamble rdoc
132 # +transaction+ calls can be nested. By default, this makes all database
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
133 # statements in the nested transaction block become part of the parent
d38644f4 »
2010-12-11 reviews commit 53bbbcc
134 # transaction. For example, the following behavior may be surprising:
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
135 #
136 # User.transaction do
137 # User.create(:username => 'Kotori')
138 # User.transaction do
139 # User.create(:username => 'Nemu')
140 # raise ActiveRecord::Rollback
141 # end
142 # end
da840d13 »
2009-06-02 Add after_commit and after_rollback callbacks to ActiveRecord that ar…
143 #
d38644f4 »
2010-12-11 reviews commit 53bbbcc
144 # creates both "Kotori" and "Nemu". Reason is the <tt>ActiveRecord::Rollback</tt>
145 # exception in the nested block does not issue a ROLLBACK. Since these exceptions
146 # are captured in transaction blocks, the parent block does not see it and the
147 # real transaction is committed.
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
148 #
d38644f4 »
2010-12-11 reviews commit 53bbbcc
149 # In order to get a ROLLBACK for the nested transaction you may ask for a real
150 # sub-transaction by passing <tt>:requires_new => true</tt>. If anything goes wrong,
151 # the database rolls back to the beginning of the sub-transaction without rolling
152 # back the parent transaction. If we add it to the previous example:
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
153 #
154 # User.transaction do
155 # User.create(:username => 'Kotori')
ab0ce052 »
2009-01-10 Introduce transaction_joinable flag to mark that the fixtures transac…
156 # User.transaction(:requires_new => true) do
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
157 # User.create(:username => 'Nemu')
158 # raise ActiveRecord::Rollback
159 # end
160 # end
da840d13 »
2009-06-02 Add after_commit and after_rollback callbacks to ActiveRecord that ar…
161 #
d38644f4 »
2010-12-11 reviews commit 53bbbcc
162 # only "Kotori" is created. (This works on MySQL and PostgreSQL, but not on SQLite3.)
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
163 #
164 # Most databases don't support true nested transactions. At the time of
165 # writing, the only database that we're aware of that supports true nested
166 # transactions, is MS-SQL. Because of this, Active Record emulates nested
d38644f4 »
2010-12-11 reviews commit 53bbbcc
167 # transactions by using savepoints on MySQL and PostgreSQL. See
196c8f13 »
2011-06-01 Edited activerecord/lib/active_record/transactions.rb via GitHub
168 # http://dev.mysql.com/doc/refman/5.0/en/savepoint.html
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
169 # for more information about savepoints.
170 #
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
171 # === Callbacks
172 #
173 # There are two types of callbacks associated with committing and rolling back transactions:
174 # +after_commit+ and +after_rollback+.
175 #
176 # +after_commit+ callbacks are called on every record saved or destroyed within a
177 # transaction immediately after the transaction is committed. +after_rollback+ callbacks
178 # are called on every record saved or destroyed within a transaction immediately after the
179 # transaction or savepoint is rolled back.
180 #
181 # These callbacks are useful for interacting with other systems since you will be guaranteed
182 # that the callback is only executed when the database is in a permanent state. For example,
183 # +after_commit+ is a good spot to put in a hook to clearing a cache since clearing it from
184 # within a transaction could trigger the cache to be regenerated before the database is updated.
185 #
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
186 # === Caveats
187 #
188 # If you're on MySQL, then do not use DDL operations in nested transactions
189 # blocks that are emulated with savepoints. That is, do not execute statements
190 # like 'CREATE TABLE' inside such blocks. This is because MySQL automatically
1ff954aa »
2010-04-30 after_(commit|rollback) rdoc, edit pass
191 # releases all savepoints upon executing a DDL operation. When +transaction+
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
192 # is finished and tries to release the savepoint it created earlier, a
193 # database error will occur because the savepoint has already been
194 # automatically released. The following example demonstrates the problem:
da840d13 »
2009-06-02 Add after_commit and after_rollback callbacks to ActiveRecord that ar…
195 #
ab0ce052 »
2009-01-10 Introduce transaction_joinable flag to mark that the fixtures transac…
196 # Model.connection.transaction do # BEGIN
197 # Model.connection.transaction(:requires_new => true) do # CREATE SAVEPOINT active_record_1
198 # Model.connection.create_table(...) # active_record_1 now automatically released
199 # end # RELEASE savepoint active_record_1
200 # # ^^^^ BOOM! database error!
e916aa7e »
2008-10-09 Rename ActiveRecord::Base#transaction's :force option to :nest. Impro…
201 # end
632bbbfe »
2009-04-04 Merge docrails
202 #
203 # Note that "TRUNCATE" is also a MySQL DDL statement!
50562c2a »
2004-12-30 Restored thread safety to Active Record [andreas]
204 module ClassMethods
6e754551 »
2008-07-28 Merge docrails changes
205 # See ActiveRecord::Transactions::ClassMethods for detailed documentation.
b3420f5a »
2008-08-31 Implement savepoints.
206 def transaction(options = {}, &block)
ab0ce052 »
2009-01-10 Introduce transaction_joinable flag to mark that the fixtures transac…
207 # See the ConnectionAdapters::DatabaseStatements#transaction API docs.
208 connection.transaction(options, &block)
db045dbb »
2004-11-24 Initial
209 end
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
210
cabab374 »
2012-08-30 documents after_(commit|rollback)
211 # This callback is called after a record has been created, updated, or destroyed.
212 #
213 # You can specify that the callback should only be fired by a certain action with
214 # the +:on+ option:
215 #
216 # after_commit :do_foo, :on => :create
217 # after_commit :do_bar, :on => :update
218 # after_commit :do_baz, :on => :destroy
219 #
220 # Also, to have the callback fired on create and update, but not on destroy:
221 #
222 # after_commit :do_zoo, :if => :persisted?
223 #
224 # Note that transactional fixtures do not play well with this feature. Please
225 # use the +test_after_commit+ gem to have these hooks fired in tests.
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
226 def after_commit(*args, &block)
227 options = args.last
228 if options.is_a?(Hash) && options[:on]
229 options[:if] = Array.wrap(options[:if])
230 options[:if] << "transaction_include_action?(:#{options[:on]})"
231 end
232 set_callback(:commit, :after, *args, &block)
233 end
234
cabab374 »
2012-08-30 documents after_(commit|rollback)
235 # This callback is called after a create, update, or destroy are rolled back.
236 #
237 # Please check the documentation of +after_commit+ for options.
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
238 def after_rollback(*args, &block)
239 options = args.last
240 if options.is_a?(Hash) && options[:on]
241 options[:if] = Array.wrap(options[:if])
242 options[:if] << "transaction_include_action?(:#{options[:on]})"
243 end
244 set_callback(:rollback, :after, *args, &block)
245 end
db045dbb »
2004-11-24 Initial
246 end
247
a2932784 »
2008-10-05 Merge docrails
248 # See ActiveRecord::Transactions::ClassMethods for detailed documentation.
69789c3b »
2010-10-14 #transaction on the instance level should take options as well
249 def transaction(options = {}, &block)
250 self.class.transaction(options, &block)
db045dbb »
2004-11-24 Initial
251 end
252
d916c62c »
2010-05-09 eliminate alias_method_chain from ActiveRecord
253 def destroy #:nodoc:
254 with_transaction_returning_status { super }
db045dbb »
2004-11-24 Initial
255 end
629b8af2 »
2006-10-10 Wrap save! in a transaction. Closes #6324.
256
d916c62c »
2010-05-09 eliminate alias_method_chain from ActiveRecord
257 def save(*) #:nodoc:
258 rollback_active_record_state! do
259 with_transaction_returning_status { super }
260 end
db045dbb »
2004-11-24 Initial
261 end
629b8af2 »
2006-10-10 Wrap save! in a transaction. Closes #6324.
262
d916c62c »
2010-05-09 eliminate alias_method_chain from ActiveRecord
263 def save!(*) #:nodoc:
264 with_transaction_returning_status { super }
1af2022c »
2007-01-02 Rollback #new_record? and #id values for created records that rollbac…
265 end
3b6555ac »
2007-01-12 Fix new_record? and id rollback. Closes #6910.
266
e444439f »
2010-11-28 Partialy revert f1c13b0
267 # Reset id and @new_record if the transaction rolls back.
3b6555ac »
2007-01-12 Fix new_record? and id rollback. Closes #6910.
268 def rollback_active_record_state!
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
269 remember_transaction_record_state
3b6555ac »
2007-01-12 Fix new_record? and id rollback. Closes #6910.
270 yield
271 rescue Exception
e88fd023 »
2010-09-13 Remove object from identity map if transaction failed.
272 IdentityMap.remove(self) if IdentityMap.enabled?
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
273 restore_transaction_record_state
274 raise
275 ensure
276 clear_transaction_record_state
277 end
278
279 # Call the after_commit callbacks
280 def committed! #:nodoc:
57bc25c5 »
2011-01-09 Use run_callbacks; the generated _run_<name>_callbacks method is not …
281 run_callbacks :commit
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
282 ensure
283 clear_transaction_record_state
284 end
285
286 # Call the after rollback callbacks. The restore_state argument indicates if the record
287 # state should be rolled back to the beginning or just to the last savepoint.
288 def rolledback!(force_restore_state = false) #:nodoc:
57bc25c5 »
2011-01-09 Use run_callbacks; the generated _run_<name>_callbacks method is not …
289 run_callbacks :rollback
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
290 ensure
b3561723 »
2011-04-03 Use IM when trying to load records using ID.
291 IdentityMap.remove(self) if IdentityMap.enabled?
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
292 restore_transaction_record_state(force_restore_state)
293 end
294
295 # Add the record to the current transaction so that the :after_rollback and :after_commit callbacks
296 # can be called.
297 def add_to_transaction
298 if self.class.connection.add_transaction_record(self)
299 remember_transaction_record_state
8b5f4e47 »
2007-12-22 Ruby 1.9 compat: fix warnings, shadowed block vars, and unitialized i…
300 end
629b8af2 »
2006-10-10 Wrap save! in a transaction. Closes #6324.
301 end
e02f0dcc »
2008-08-24 Rollback the transaction when a before_* callback returns false.
302
303 # Executes +method+ within a transaction and captures its return value as a
304 # status flag. If the status is true the transaction is committed, otherwise
305 # a ROLLBACK is issued. In any case the status flag is returned.
a2932784 »
2008-10-05 Merge docrails
306 #
307 # This method is available within the context of an ActiveRecord::Base
308 # instance.
d916c62c »
2010-05-09 eliminate alias_method_chain from ActiveRecord
309 def with_transaction_returning_status
e02f0dcc »
2008-08-24 Rollback the transaction when a before_* callback returns false.
310 status = nil
455c7f9e »
2008-12-10 Don't use the transaction instance method so that people with has_one…
311 self.class.transaction do
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
312 add_to_transaction
d916c62c »
2010-05-09 eliminate alias_method_chain from ActiveRecord
313 status = yield
e02f0dcc »
2008-08-24 Rollback the transaction when a before_* callback returns false.
314 raise ActiveRecord::Rollback unless status
315 end
316 status
317 end
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
318
319 protected
320
321 # Save the new record state and id of a record so it can be restored later if a transaction fails.
94dcbe81 »
2011-12-09 fix nodocs
322 def remember_transaction_record_state #:nodoc:
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
323 @_start_transaction_state ||= {}
64747654 »
2011-10-05 Revert "Raise error on unknown primary key."
324 @_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key)
e444439f »
2010-11-28 Partialy revert f1c13b0
325 unless @_start_transaction_state.include?(:new_record)
326 @_start_transaction_state[:new_record] = @new_record
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
327 end
328 unless @_start_transaction_state.include?(:destroyed)
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
329 @_start_transaction_state[:destroyed] = @destroyed
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
330 end
331 @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
f7c2a811 »
2012-10-22 frozen state should be restored after txn is aborted
332 @_start_transaction_state[:frozen?] = @attributes.frozen?
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
333 end
334
335 # Clear the new record state and id of a record.
94dcbe81 »
2011-12-09 fix nodocs
336 def clear_transaction_record_state #:nodoc:
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
337 if defined?(@_start_transaction_state)
338 @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1
339 remove_instance_variable(:@_start_transaction_state) if @_start_transaction_state[:level] < 1
340 end
341 end
342
343 # Restore the new record state and id of a record that was previously saved by a call to save_record_state.
94dcbe81 »
2011-12-09 fix nodocs
344 def restore_transaction_record_state(force = false) #:nodoc:
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
345 if defined?(@_start_transaction_state)
346 @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1
786713a3 »
2012-08-11 Merge pull request #6073 from daveyeu/restore-state-on-record-invalid
347 if @_start_transaction_state[:level] < 1 || force
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
348 restore_state = remove_instance_variable(:@_start_transaction_state)
f7c2a811 »
2012-10-22 frozen state should be restored after txn is aborted
349 was_frozen = restore_state[:frozen?]
350 @attributes = @attributes.dup if @attributes.frozen?
9d549986 »
2011-01-17 remove useless conditional
351 @new_record = restore_state[:new_record]
352 @destroyed = restore_state[:destroyed]
353 if restore_state.has_key?(:id)
354 self.id = restore_state[:id]
355 else
356 @attributes.delete(self.class.primary_key)
357 @attributes_cache.delete(self.class.primary_key)
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
358 end
a5430024 »
2012-05-22 Restore the frozen state on rollback. Fixes #6417.
359 @attributes.freeze if was_frozen
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
360 end
361 end
362 end
363
364 # Determine if a record was created or destroyed in a transaction. State should be one of :new_record or :destroyed.
94dcbe81 »
2011-12-09 fix nodocs
365 def transaction_record_state(state) #:nodoc:
b0707392 »
2010-06-08 Revert "Temporarily revert "Update after_commit and after_rollback do…
366 @_start_transaction_state[state] if defined?(@_start_transaction_state)
367 end
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
368
369 # Determine if a transaction included an action for :create, :update, or :destroy. Used in filtering callbacks.
94dcbe81 »
2011-12-09 fix nodocs
370 def transaction_include_action?(action) #:nodoc:
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
371 case action
372 when :create
e444439f »
2010-11-28 Partialy revert f1c13b0
373 transaction_record_state(:new_record)
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
374 when :destroy
375 destroyed?
376 when :update
e444439f »
2010-11-28 Partialy revert f1c13b0
377 !(transaction_record_state(:new_record) || destroyed?)
2500e6af »
2010-06-08 Make logic for after_commit and after_rollback :on option work like i…
378 end
379 end
db045dbb »
2004-11-24 Initial
380 end
098fa943 »
2005-02-07 Fixed documentation snafus #575, #576, #577, #585
381 end
Something went wrong with that request. Please try again.