From f31670d0270342f37846082ac1a27fc6d3400a8a Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 15 Mar 2012 18:27:43 +0000 Subject: when using a preloaded array and the uniq flag is set then return the size of the uniq array --- .../lib/active_record/associations/collection_association.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index da4c311bce..08d53d8c56 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -248,8 +248,12 @@ module ActiveRecord # This method is abstract in the sense that it relies on # +count_records+, which is a method descendants have to provide. def size - if !find_target? || (loaded? && !options[:uniq]) - target.size + if !find_target? || loaded? + if options[:uniq] + target.uniq.size + else + target.size + end elsif !loaded? && options[:group] load_target.size elsif !loaded? && !options[:uniq] && target.is_a?(Array) -- cgit v1.2.3