Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Add soft delete to ActiveRecord
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
MIT-LICENSE
Manifest
README
Rakefile
delete_softly.gemspec
init.rb
install.rb
uninstall.rb

README

DeleteSoftly
============

Add soft delete functionality to ActiveRecord models. Important information:
This is Rails3 only, no backwards compatibility. Important features are
* It works through relations
* papertrail support

Tested with Postgresql

New in version 0.3
* without_deleted, same as active, but not meant to be overwritten
* deleted is back, misteriously disappeared in version 0.2

Example
=======
 class Post
   # Replace normal behavior of object completely
   delete_softly
 end

 class Comment
   # Rely on calling active for this object when needed
   delete_softly false
 end
 
Now the following stuff works:
== The Post model == 
 p1 = Post.create
 p2 = Post.create
 Post.count #=> 2
 p2.destroy
 Post.count #=> 1
 Post.at_time(1.year.ago).count #=> 0

 c1 = Comment.create
 c2 = Comment.create
 Comment.count #=> 2
 c1.destroy
 Comment.count #=> 2 (Since we added false)
 Comment.active.count #=> 1
 
See the rdoc for better examples and documentation

Copyright (c) 2010 [Benjamin ter Kuile], released under the MIT license
Something went wrong with that request. Please try again.