From 2ff5f38abb4a44ed5356c34b40d30d446fb63408 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 14 Apr 2010 01:51:43 +0100 Subject: Ensure not to load the entire association when bulk updating existing records using nested attributes --- .../associations/association_collection.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'activerecord/lib/active_record/associations/association_collection.rb') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 6a4cef0d50..0dfd966466 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -451,6 +451,16 @@ module ActiveRecord records end + def add_record_to_target_with_callbacks(record) + callback(:before_add, record) + yield(record) if block_given? + @target ||= [] unless loaded? + @target << record unless @reflection.options[:uniq] && @target.include?(record) + callback(:after_add, record) + set_inverse_instance(record, @owner) + record + end + private def create_record(attrs) attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash) @@ -475,16 +485,6 @@ module ActiveRecord end end - def add_record_to_target_with_callbacks(record) - callback(:before_add, record) - yield(record) if block_given? - @target ||= [] unless loaded? - @target << record unless @reflection.options[:uniq] && @target.include?(record) - callback(:after_add, record) - set_inverse_instance(record, @owner) - record - end - def remove_records(*records) records = flatten_deeper(records) records.each { |record| raise_on_type_mismatch(record) } -- cgit v1.2.3