aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-24 23:43:44 +0000
committerJon Leighton <j@jonathanleighton.com>2011-01-30 11:58:08 +0000
commit2e24cf7cc2392c8fa252ef3b4831a4516ae852d6 (patch)
tree2d58988ca33921ad8823505b66c1479888bd5e0d /activerecord/lib/active_record
parent88df88095c82cde53501abe2a44f6c1f66c272b4 (diff)
downloadrails-2e24cf7cc2392c8fa252ef3b4831a4516ae852d6.tar.gz
rails-2e24cf7cc2392c8fa252ef3b4831a4516ae852d6.tar.bz2
rails-2e24cf7cc2392c8fa252ef3b4831a4516ae852d6.zip
AssociationCollection#clear can basically just use #delete_all, except it should return self.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb20
1 files changed, 7 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index f2997b9db3..8e63159190 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -112,6 +112,13 @@ module ActiveRecord
end
end
+ # Identical to delete_all, except that the return value is the association (for chaining)
+ # rather than the records which have been removed.
+ def clear
+ delete_all
+ self
+ end
+
# Destroy all the records from this association.
#
# See destroy for more info.
@@ -191,19 +198,6 @@ module ActiveRecord
load_target
end
- # Removes all records from this association. Returns +self+ so method calls may be chained.
- def clear
- unless length.zero? # forces load_target if it hasn't happened already
- if @reflection.options[:dependent] == :destroy
- destroy_all
- else
- delete_all
- end
- end
-
- self
- end
-
def create(attrs = {})
if attrs.is_a?(Array)
attrs.collect { |attr| create(attr) }