aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-03-30 14:39:55 +0100
committerJon Leighton <j@jonathanleighton.com>2012-03-30 14:39:55 +0100
commit1ce75450a9fba33edf2bffee0bf0ac3d31ea677f (patch)
tree5257cdf7c768b0afbdcdc45026a35c4e5b2a45c0 /activerecord/lib/active_record/persistence.rb
parent43f9622c6749d04867534e1a8838df619c2a79f0 (diff)
downloadrails-1ce75450a9fba33edf2bffee0bf0ac3d31ea677f.tar.gz
rails-1ce75450a9fba33edf2bffee0bf0ac3d31ea677f.tar.bz2
rails-1ce75450a9fba33edf2bffee0bf0ac3d31ea677f.zip
clear up duplication between Persistence#destroy and Locking#destroy
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb30
1 files changed, 17 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 35c922e979..bb504ae90f 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -124,19 +124,7 @@ module ActiveRecord
# that no changes should be made (since they can't be persisted).
def destroy
destroy_associations
-
- if persisted?
- pk = self.class.primary_key
- column = self.class.columns_hash[pk]
- substitute = connection.substitute_at(column, 0)
-
- relation = self.class.unscoped.where(
- self.class.arel_table[pk].eq(substitute))
-
- relation.bind_values = [[column, id]]
- relation.delete_all
- end
-
+ destroy_row if persisted?
@destroyed = true
freeze
end
@@ -335,6 +323,22 @@ module ActiveRecord
def destroy_associations
end
+ def destroy_row
+ relation_for_destroy.delete_all
+ end
+
+ def relation_for_destroy
+ pk = self.class.primary_key
+ column = self.class.columns_hash[pk]
+ substitute = connection.substitute_at(column, 0)
+
+ relation = self.class.unscoped.where(
+ self.class.arel_table[pk].eq(substitute))
+
+ relation.bind_values = [[column, id]]
+ relation
+ end
+
def create_or_update
raise ReadOnlyRecord if readonly?
result = new_record? ? create : update