diff options
author | Jon Rowe <hello@jonrowe.co.uk> | 2012-03-15 18:27:43 +0000 |
---|---|---|
committer | Jon Rowe <hello@jonrowe.co.uk> | 2012-03-15 19:18:31 +0000 |
commit | f31670d0270342f37846082ac1a27fc6d3400a8a (patch) | |
tree | 060604c109ef1fb91a248f707c6c2b0ecf9e3799 /activerecord/lib | |
parent | fbc9d0f44f090a9873834f4966760c3e80682559 (diff) | |
download | rails-f31670d0270342f37846082ac1a27fc6d3400a8a.tar.gz rails-f31670d0270342f37846082ac1a27fc6d3400a8a.tar.bz2 rails-f31670d0270342f37846082ac1a27fc6d3400a8a.zip |
when using a preloaded array and the uniq flag is set then return the size of the uniq array
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 8 |
1 files changed, 6 insertions, 2 deletions
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) |