Skip to content

Commit

Permalink
updated some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Chupp committed Apr 27, 2009
1 parent c89d04e commit d16e3c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,5 +1,8 @@
This will only document major changes. Please see the commit log for minor changes.

-2009-04-27
* restoring models now cascades to child dependent => destroy models via Matt Todd

-2009-04-22
* destroying and restoring records no longer triggers saving/updating callbacks

Expand Down
8 changes: 7 additions & 1 deletion lib/is_paranoid.rb
Expand Up @@ -56,7 +56,13 @@ def destroy
end

# Use update_all with an exclusive scope to restore undo the soft-delete.
# This bypasses update-related callbacks
# This bypasses update-related callbacks.
#
# By default, restores cascade through associations that are
# :dependent => :destroy and under is_paranoid. You can prevent restoration
# of associated models by passing :include_destroyed_dependents => false,
# for example:
# Android.restore(:include_destroyed_dependents => false)
def self.restore(id, options = {})
options.reverse_merge!({:include_destroyed_dependents => true})
with_exclusive_scope do
Expand Down
18 changes: 9 additions & 9 deletions spec/is_paranoid_spec.rb
@@ -1,11 +1,11 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

class Person < ActiveRecord::Base
class Person < ActiveRecord::Base #:nodoc:
validates_uniqueness_of :name
has_many :androids, :foreign_key => :owner_id, :dependent => :destroy
end

class Android < ActiveRecord::Base
class Android < ActiveRecord::Base #:nodoc:
validates_uniqueness_of :name
has_many :components, :dependent => :destroy

Expand All @@ -17,11 +17,11 @@ def raise_hell
end
end

class Component < ActiveRecord::Base
class Component < ActiveRecord::Base #:nodoc:
is_paranoid
end

class AndroidWithScopedUniqueness < ActiveRecord::Base
class AndroidWithScopedUniqueness < ActiveRecord::Base #:nodoc:
set_table_name :androids
validates_uniqueness_of :name, :scope => :deleted_at
is_paranoid
Expand Down Expand Up @@ -140,29 +140,29 @@ class AndroidWithScopedUniqueness < ActiveRecord::Base
end
end

class Ninja < ActiveRecord::Base
class Ninja < ActiveRecord::Base #:nodoc:
validates_uniqueness_of :name, :scope => :visible
is_paranoid :field => [:visible, false, true]
end

class Pirate < ActiveRecord::Base
class Pirate < ActiveRecord::Base #:nodoc:
is_paranoid :field => [:alive, false, true]
end

class DeadPirate < ActiveRecord::Base
class DeadPirate < ActiveRecord::Base #:nodoc:
set_table_name :pirates
is_paranoid :field => [:alive, true, false]
end

class RandomPirate < ActiveRecord::Base
class RandomPirate < ActiveRecord::Base #:nodoc:
set_table_name :pirates

def after_destroy
raise 'after_destroy works'
end
end

class UndestroyablePirate < ActiveRecord::Base
class UndestroyablePirate < ActiveRecord::Base #:nodoc:
set_table_name :pirates
is_paranoid :field => [:alive, false, true]

Expand Down

0 comments on commit d16e3c9

Please sign in to comment.