Permalink
Browse files

Merge pull request #82 from chuckbergeron/fix/activerecord_persisted

Retains the original ActiveRecord behaviour for #persisted? ...
  • Loading branch information...
2 parents ddcca61 + 6d37972 commit aa0657a928f4db0923e6ccfc730ef852d050840d @goncalossilva committed Nov 28, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/acts_as_paranoid/core.rb
@@ -81,6 +81,10 @@ def without_paranoid_default_scope
end
end
+ def persisted?
+ !(new_record? || @destroyed)
+ end
+
def paranoid_value
self.send(self.class.paranoid_column)
end
@@ -131,7 +135,7 @@ def recover_dependent_associations(window, options)
next unless reflection.klass.paranoid?
scope = reflection.klass.only_deleted
-
+
# Merge in the association's scope
scope = scope.merge(association(reflection.name).association_scope)
@@ -146,13 +150,13 @@ def recover_dependent_associations(window, options)
end
end
end
-
+
def destroy_dependent_associations!
self.class.dependent_associations.each do |reflection|
next unless reflection.klass.paranoid?
scope = reflection.klass.only_deleted
-
+
# Merge in the association's scope
scope = scope.merge(association(reflection.name).association_scope)
@@ -163,7 +167,7 @@ def destroy_dependent_associations!
end
def deleted?
- !(paranoid_value.nil? ||
+ !(paranoid_value.nil? ||
(self.class.string_type_with_deleted_value? && paranoid_value != self.class.delete_now_value))
end

0 comments on commit aa0657a

Please sign in to comment.