diff options
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 8 |
2 files changed, 4 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 9c27411a3e..61ad6ab7b6 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -98,8 +98,8 @@ module ActiveRecord if loaded? && !@reflection.options[:uniq] @target.size elsif !loaded? && !@reflection.options[:uniq] && @target.is_a?(Array) - unsaved_records = Array(@target.detect { |r| r.new_record? }).size - unsaved_records + count_records + unsaved_records = Array(@target.detect { |r| r.new_record? }) + unsaved_records.size + count_records else count_records end diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 6a2089c7b8..660e005348 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -13,12 +13,8 @@ module ActiveRecord record = @reflection.klass.new(attributes) set_belongs_to_association_for(record) - if loaded? - @target << record - else - @target ||= [] - @target << record - end + @target ||= [] unless loaded? + @target << record record end |