Skip to content

Instantly share code, notes, and snippets.

@alvin2ye
Created March 25, 2010 07:47
Show Gist options
  • Save alvin2ye/343293 to your computer and use it in GitHub Desktop.
Save alvin2ye/343293 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.quoted_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