See ActiveRecord::Transactions::ClassMethods for documentation.
- A
- C
- R
- T
- W
Add the record to the current transaction so that the :after_rollback and :after_commit callbacks can be called.
Reset id and @new_record if the transaction rolls back.
# File activerecord/lib/active_record/transactions.rb, line 250 def rollback_active_record_state! remember_transaction_record_state yield rescue Exception IdentityMap.remove(self) if IdentityMap.enabled? restore_transaction_record_state raise ensure clear_transaction_record_state end
See ActiveRecord::Transactions::ClassMethods for detailed documentation.
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.
Clear the new record state and id of a record.
# File activerecord/lib/active_record/transactions.rb, line 317 def clear_transaction_record_state #:nodoc if defined?(@_start_transaction_state) @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1 remove_instance_variable(:@_start_transaction_state) if @_start_transaction_state[:level] < 1 end end
Save the new record state and id of a record so it can be restored later if a transaction fails.
# File activerecord/lib/active_record/transactions.rb, line 304 def remember_transaction_record_state #:nodoc @_start_transaction_state ||= {} @_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key) unless @_start_transaction_state.include?(:new_record) @_start_transaction_state[:new_record] = @new_record end unless @_start_transaction_state.include?(:destroyed) @_start_transaction_state[:destroyed] = @destroyed end @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1 end
Restore the new record state and id of a record that was previously saved by a call to save_record_state.
# File activerecord/lib/active_record/transactions.rb, line 325 def restore_transaction_record_state(force = false) #:nodoc if defined?(@_start_transaction_state) @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1 if @_start_transaction_state[:level] < 1 restore_state = remove_instance_variable(:@_start_transaction_state) @attributes = @attributes.dup if @attributes.frozen? @new_record = restore_state[:new_record] @destroyed = restore_state[:destroyed] if restore_state.has_key?(:id) self.id = restore_state[:id] else @attributes.delete(self.class.primary_key) @attributes_cache.delete(self.class.primary_key) end end end end
Determine if a transaction included an action for :create, :update, or :destroy. Used in filtering callbacks.
# File activerecord/lib/active_record/transactions.rb, line 349 def transaction_include_action?(action) #:nodoc case action when :create transaction_record_state(:new_record) when :destroy destroyed? when :update !(transaction_record_state(:new_record) || destroyed?) end end
Determine if a record was created or destroyed in a transaction. State should be one of :new_record or :destroyed.