def size
if loaded?
@records.length
else
count_value = count(:all)
count_value.is_a?(Hash) ? count_value.length : count_value
end
end
# 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
--
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-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
g = User.group(:role); g.load; g.count
=> {:normal=>3, :admin=>4}
g = User.group(:role); g.load; g.size
=> 2
g = User.group(:role); g.load; g.count
=> {:normal=>3, :admin=>4}
g = User.group(:role); g.load; g.size
=>{:normal=>3, :admin=>4}
g = User.group(:role); g.load; g.count
=> 2
g = User.group(:role); g.load; g.size
=>2
User.count
User.group(:role).count.values.sum
That's why I said that In this specific case it was like an "alias", not exactly an alias. Count will always query the DB anyway, but let's hear more thoughts on this one.
Carlos Antonio da Silva - via celular
c = User.group(:role).count
=> {:normal=>3, :admin=>4}
c.values.sum=> 7
--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/2BELBVaNEeA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.