Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

ActiveRecord plugin which allows you to hide without actually deleting them for Rails3.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 millstone.gemspec
README.md

Millstone

ActiveRecord plugin which hides records instead of deleting them for Rails3

Millstone is extending ActiveRecord::Relation

Credits

This plugin was inspired by rails3_acts_as_paranoid and acts_as_paranoid.

Usage

class User < ActiveRecord::Base
  millstone
end

Options

  • :column => 'deleted_at'
  • :type => 'time'

Filtering

User.all          # retrieves the non-deleted records
User.only_deleted # retrieves the deleted records
User.with_deleted # retrieves all records, deleted or not

Real deletion

user.destroy!
user.delete_all!(conditions)

Validation

class User < ActiveRecord::Base
  acts_as_paranoid
  validates_uniqueness_of :name
end

User.create(:name => 'foo').destroy
User.new(:name => 'foo').valid? #=> true


class User < ActiveRecord::Base
  acts_as_paranoid
  validates_uniqueness_of_with_deleted :name
end

User.create(:name => 'foo').destroy
User.new(:name => 'foo').valid? #=> false

Status

user = User.create(:name => 'foo')
user.deleted? #=> false
user.destroy
User.with_deleted.first.deleted? #=> true

Association options

class Parent < ActiveRecord::Base
  acts_as_pranoid
  has_many :children
end

class Child < ActiveRecord::Base
  acts_as_paranoid
  belongs_to :parent
end

parent = Parent.create(:name => "foo")
child = parent.children.create!(:name => "bar")
parent.destroy
child.parent # => nil


class Child < ActiveRecord::Base
  acts_as_paranoid
  belongs_to :parent, :with_deleted => true
end

parent = Parent.create(:name => "foo")
child = parent.children.create!(:name => "bar")
parent.destroy
child.parent #=> #<Parent ... deleted_at: deleted_time>
child.parent.deleted? #=> true

Copyright © 2011 Yoshikazu Ozawa, released under the MIT license

Something went wrong with that request. Please try again.