Skip to content

Instantly share code, notes, and snippets.

@alvin2ye
Forked from alvin2ye/add_delete.rb
Created March 25, 2010 08:35
Show Gist options
  • Save alvin2ye/343317 to your computer and use it in GitHub Desktop.
Save alvin2ye/343317 to your computer and use it in GitHub Desktop.
# http://gist.github.com/343293
# it's for rails 1.2.5
# add require 'add_delete.rb' in environment.rb
class ActiveRecord::Base
def delete!
unless new_record?
affected_rows = connection.delete("DELETE FROM `#{self.class.table_name}` WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id}", "#{self.class.name} Destroy")
unless affected_rows == 1
raise ActiveRecord::StaleObjectError, "Attempted to delete a stale object"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment