Soft Deletes

How would I go about setting up my rails applications to soft delete
items from the database rather than actually deleting it. I would
imagine that I need to over ride the methods from ActiveRecord.

Where would I do this would it be in the model? enviroment.rb? I
would imagine that if i wanted it throughout my entire application it
would need to be in the enviroment.rb.

Also to en-corporate the soft deletes I might need to write some
custom find methods etc.

Has anyone got any ideas. Or has a plugin (etc) been written already?

Many thanks

Cheers, thats exactly what I was looking for.

A somehwat brutish approach might be to not actually use the rails
destroy method, but instead do something like this. It all depends on
how complex your app/domain is I suppose:

class Thingy < ActiveRecord::Base
def Thingy.active
Thingy.get_thingys
end

def Thingy.archived
Thingy. get_thingys(1)
end

def Thingy.all
Thingy.find(:all)
end

def Thingy. get_thingys(archived = 0)
Thingy.find(:all, :conditions => “archived = #{archived.to_s}”)
end

def archive
self.archived = 1
end
end

On 1/16/06, Oliver L. [email protected] wrote:

Has anyone got any ideas. Or has a plugin (etc) been written already?

Many thanks


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Lance B.
http://lance.langwell-ball.com

Check out the “acts_as_paranoid” plugin. It handles soft deletes for
any ActiveRecord marked “acts_as_paranoid”.

http://wiki.rubyonrails.com/rails/pages/Plugins

acts_as_paranoid

http://ar-paranoid.rubyforge.org/

On 1/16/06, Theodore M. [email protected] wrote:

Check out the “acts_as_paranoid” plugin. It handles soft deletes for
any ActiveRecord marked “acts_as_paranoid”.

Peak Obsession

Ahh - nice.


Lance B.
http://lance.langwell-ball.com