Module: ActiveRecord::Transactions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- activerecord/lib/active_record/transactions.rb
Overview
See ActiveRecord::Transactions::ClassMethods for documentation.
Defined Under Namespace
Modules: ClassMethods Classes: TransactionError
Instance Method Summary (collapse)
-
- (Object) add_to_transaction
Add the record to the current transaction so that the :after_rollback and :after_commit callbacks can be called.
-
- (Object) committed!
Call the after_commit callbacks.
-
- (Object) destroy
:nodoc:.
-
- (Object) rollback_active_record_state!
Reset id and @new_record if the transaction rolls back.
-
- (Object) rolledback!(force_restore_state = false)
Call the after rollback callbacks.
-
- (Object) save
:nodoc:.
-
- (Object) save!
:nodoc:.
-
- (Object) transaction(&block)
See ActiveRecord::Transactions::ClassMethods for detailed documentation.
-
- (Object) with_transaction_returning_status
Executes method within a transaction and captures its return value as a status flag.
Methods included from ActiveSupport::Concern
append_features, extended, included
Instance Method Details
- (Object) add_to_transaction
Add the record to the current transaction so that the :after_rollback and :after_commit callbacks can be called.
273 274 275 276 277 |
# File 'activerecord/lib/active_record/transactions.rb', line 273 def add_to_transaction if self.class.connection.add_transaction_record(self) remember_transaction_record_state end end |
- (Object) committed!
Call the after_commit callbacks
257 258 259 260 261 |
# File 'activerecord/lib/active_record/transactions.rb', line 257 def committed! #:nodoc: _run_commit_callbacks ensure clear_transaction_record_state end |
- (Object) destroy
:nodoc:
231 232 233 |
# File 'activerecord/lib/active_record/transactions.rb', line 231 def destroy #:nodoc: with_transaction_returning_status { super } end |
- (Object) rollback_active_record_state!
Reset id and @new_record if the transaction rolls back.
246 247 248 249 250 251 252 253 254 |
# File 'activerecord/lib/active_record/transactions.rb', line 246 def rollback_active_record_state! remember_transaction_record_state yield rescue Exception restore_transaction_record_state raise ensure clear_transaction_record_state end |
- (Object) rolledback!(force_restore_state = false)
Call the after rollback callbacks. The restore_state argument indicates if the record state should be rolled back to the beginning or just to the last savepoint.
265 266 267 268 269 |
# File 'activerecord/lib/active_record/transactions.rb', line 265 def rolledback!(force_restore_state = false) #:nodoc: _run_rollback_callbacks ensure restore_transaction_record_state(force_restore_state) end |
- (Object) save
:nodoc:
235 236 237 238 239 |
# File 'activerecord/lib/active_record/transactions.rb', line 235 def save(*) #:nodoc: rollback_active_record_state! do with_transaction_returning_status { super } end end |
- (Object) save!
:nodoc:
241 242 243 |
# File 'activerecord/lib/active_record/transactions.rb', line 241 def save!(*) #:nodoc: with_transaction_returning_status { super } end |
- (Object) transaction(&block)
See ActiveRecord::Transactions::ClassMethods for detailed documentation.
227 228 229 |
# File 'activerecord/lib/active_record/transactions.rb', line 227 def transaction(&block) self.class.transaction(&block) end |
- (Object) with_transaction_returning_status
Executes method within a transaction and captures its return value as a status flag. If the status is true the transaction is committed, otherwise a ROLLBACK is issued. In any case the status flag is returned.
This method is available within the context of an ActiveRecord::Base instance.
285 286 287 288 289 290 291 292 293 |
# File 'activerecord/lib/active_record/transactions.rb', line 285 def with_transaction_returning_status status = nil self.class.transaction do add_to_transaction status = yield raise ActiveRecord::Rollback unless status end status end |