Acts As Paranoid plugin

Plugin details

Overrides some basic methods for the current model so that calling #destroy sets a 'deleted_at' field to the
current timestamp. ActiveRecord is required.

Websitehttp://rubyforge.org/projects/ar-paranoid Repositoryhttp://svn.techno-weenie.net/projects/plugins/acts_as_paranoid/ Author Rick Olson Tags ActiveRecord, Version LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid/

Overrides some basic methods for the current model so that calling destroy sets a ‘deleted_at’ field to the current timestamp. This assumes the table has a deleted_at date/time field. Most normal model operations will work, but there will be some oddities.

class Widget < ActiveRecord::Base
  acts_as_paranoid
end

Widget.find(:all)
# SELECT * FROM widgets WHERE widgets.deleted_at IS NULL

Widget.find(:first, :conditions => ['title = ?', 'test'], :order => 'title')
# SELECT * FROM widgets WHERE widgets.deleted_at IS NULL AND title = 'test' ORDER BY title LIMIT 1

Widget.find_with_deleted(:all)
# SELECT * FROM widgets

Widget.find(:all, :with_deleted => true)
# SELECT * FROM widgets

Widget.count
# SELECT COUNT(*) FROM widgets WHERE widgets.deleted_at IS NULL

Widget.count ['title = ?', 'test']
# SELECT COUNT(*) FROM widgets WHERE widgets.deleted_at IS NULL AND title = 'test'

Widget.count_with_deleted
# SELECT COUNT(*) FROM widgets

@widget.destroy
# UPDATE widgets SET deleted_at = '2005-09-17 17:46:36' WHERE id = 1

@widget.destroy!
# DELETE FROM widgets WHERE id = 1

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: maxim_kulkin, 10 months ago