ActiveRecord::Relation.size returns a Hash when I use a group method.
I think that a size method is expected to return integer typically.

I propose this  implementation:

    def size
      if loaded?
        @records.length
      else
        count_value = count(:all)
        count_value.is_a?(Hash) ? count_value.length : count_value
      end
    end

This is a current implementation:

# 
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation.rb
    # Returns size of the records.
    def size
      loaded? ? @records.length : count(:all)
    end


A count method is implemented on calculations.rb.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb


What do you think?

Thank you

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to