Flowdock
method

destroy_with_lock

Importance_0
v2.3.2 - Show latest stable - 0 notes - Class: ActiveRecord::Locking::Optimistic
destroy_with_lock(#:nodoc:) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/locking/optimistic.rb, line 113
  def destroy_with_lock #:nodoc:
    return destroy_without_lock unless locking_enabled?

    unless new_record?
      lock_col = self.class.locking_column
      previous_value = send(lock_col).to_i

      affected_rows = connection.delete(
        "DELETE FROM #{self.class.quoted_table_name} " +
        "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id} " +
              "AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}",
        "#{self.class.name} Destroy"
      )

      unless affected_rows == 1
        raise ActiveRecord::StaleObjectError, "Attempted to delete a stale object"
      end
    end

    freeze
  end
Register or log in to add new notes.