Forum: Ruby on Rails Soft Deletes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0f1e2ec122971063c71677aa03bfe038?d=identicon&s=25 Oliver Legg (Guest)
on 2006-01-17 01:27
(Received via mailing list)
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
0f1e2ec122971063c71677aa03bfe038?d=identicon&s=25 Oliver Legg (Guest)
on 2006-01-17 01:58
(Received via mailing list)
Cheers, thats exactly what I was looking for.
D046cca1a33655b6285065ec89711389?d=identicon&s=25 Lance Ball (Guest)
on 2006-01-21 15:40
(Received via mailing list)
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:
>
> 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
90bedc2d9234191f2b35dcb9fbbc4390?d=identicon&s=25 Theodore Mills (Guest)
on 2006-01-21 15:40
(Received via mailing list)
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
97cbca14d17274370cce501bbea7980a?d=identicon&s=25 Mike Harris (Guest)
on 2006-01-21 15:40
(Received via mailing list)
D046cca1a33655b6285065ec89711389?d=identicon&s=25 Lance Ball (Guest)
on 2006-01-21 15:40
(Received via mailing list)
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/Plugins

Ahh - nice.

--
Lance Ball
http://lance.langwell-ball.com
This topic is locked and can not be replied to.