Permalink
Browse files

Merge pull request #39 from codeout/rails31

association.foreign_key instead of association.primary_key_name for future compatibility
  • Loading branch information...
2 parents 8776a06 + 7c575fa commit 655933a70e44240e9a3a7ab65985ab15daf806ae @goncalossilva goncalossilva committed Sep 24, 2011
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/rails3_acts_as_paranoid.rb
@@ -154,12 +154,12 @@ def recover_dependent_associations(window, options)
end
elsif association.macro == :has_one && association.klass.paranoid?
association.klass.unscoped do
- object = association.klass.paranoid_deleted_around_time(paranoid_value, window).send('find_by_'+association.primary_key_name, self.id)
+ object = association.klass.paranoid_deleted_around_time(paranoid_value, window).send('find_by_'+association.foreign_key, self.id)
object.recover(options) if object && object.respond_to?(:recover)
end
elsif association.klass.paranoid?
association.klass.unscoped do
- id = self.send(association.primary_key_name)
+ id = self.send(association.foreign_key)
object = association.klass.paranoid_deleted_around_time(paranoid_value, window).find_by_id(id)
object.recover(options) if object && object.respond_to?(:recover)
end
@@ -170,7 +170,7 @@ def recover_dependent_associations(window, options)
def act_on_dependent_destroy_associations
self.class.dependent_associations.each do |association|
if association.collection? && self.send(association.name).paranoid?
- association.klass.with_deleted.instance_eval("find_all_by_#{association.primary_key_name}(#{self.id})").each do |object|
+ association.klass.with_deleted.instance_eval("find_all_by_#{association.foreign_key}(#{self.id})").each do |object|
object.destroy!
end
end

0 comments on commit 655933a

Please sign in to comment.