diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-04-14 01:51:43 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-04-14 01:52:29 +0100 |
commit | 2ff5f38abb4a44ed5356c34b40d30d446fb63408 (patch) | |
tree | f2c6427e5531d5b1b2515610487600a779175e0a /activerecord/lib/active_record/associations | |
parent | 5208cc3cf5d54720512ff50c2b97e9f4369aaa27 (diff) | |
download | rails-2ff5f38abb4a44ed5356c34b40d30d446fb63408.tar.gz rails-2ff5f38abb4a44ed5356c34b40d30d446fb63408.tar.bz2 rails-2ff5f38abb4a44ed5356c34b40d30d446fb63408.zip |
Ensure not to load the entire association when bulk updating existing records using nested attributes
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 20 |
1 files changed, 10 insertions, 10 deletions
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) } |