diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-12-21 23:28:12 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-12-21 23:28:12 +0000 |
commit | 4cf8bf7312a124cb96e615923ebb373380fb60bd (patch) | |
tree | 6e52754eb2bfa9e94c2648239f18d7626cdd5309 /activerecord/lib/active_record/associations | |
parent | 8cb6cb58a29b422ab7d2f2917262e40ec340816d (diff) | |
download | rails-4cf8bf7312a124cb96e615923ebb373380fb60bd.tar.gz rails-4cf8bf7312a124cb96e615923ebb373380fb60bd.tar.bz2 rails-4cf8bf7312a124cb96e615923ebb373380fb60bd.zip |
Pushing a record on an association collection doesn't unnecessarily load all the associated records.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5769 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index d3b76e2087..bda72637c3 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -7,7 +7,7 @@ module ActiveRecord load_target @target.to_ary end - + def reset reset_target! @loaded = false @@ -17,7 +17,6 @@ module ActiveRecord # Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically. def <<(*records) result = true - load_target @owner.transaction do flatten_deeper(records).each do |record| @@ -34,7 +33,7 @@ module ActiveRecord alias_method :push, :<< alias_method :concat, :<< - + # Remove all records from this association def delete_all load_target @@ -103,7 +102,7 @@ module ActiveRecord # calling collection.size if it has. If it's more likely than not that the collection does have a size larger than zero # and you need to fetch that collection afterwards, it'll take one less SELECT query if you use length. def size - if loaded? && !@reflection.options[:uniq] + if @owner.new_record? || (loaded? && !@reflection.options[:uniq]) @target.size elsif !loaded? && !@reflection.options[:uniq] && @target.is_a?(Array) unsaved_records = Array(@target.detect { |r| r.new_record? }) |