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
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 Legg <lists@51degrees.net> wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Lance Ball 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 On 1/16/06, Lance Ball <lanceball@gmail.com> wrote:> 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 Legg <lists@51degrees.net> wrote: > > 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 > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Lance Ball > http://lance.langwell-ball.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
acts_as_paranoid http://ar-paranoid.rubyforge.org/ Oliver Legg wrote:> 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 _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 1/16/06, Theodore Mills <twmills@gmail.com> 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/PluginsAhh - nice. -- Lance Ball http://lance.langwell-ball.com
Cheers, thats exactly what I was looking for. On 16 Jan 2006, at 20:20, Oliver Legg wrote:> 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_______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails