Soft Deletes


#1

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


#2

Cheers, thats exactly what I was looking for.


#3

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. removed_email_address@domain.invalid wrote:

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

Many thanks


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


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


#4

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


#5

acts_as_paranoid

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


#6

On 1/16/06, Theodore M. removed_email_address@domain.invalid wrote:

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

Ahh - nice.


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