On Nov 26, 4:03 pm, "Mohnish J." <[email protected]> wrote:
> Frederick Cheung wrote in post #1033717:
> Hi Fred,
>
> Kindly correct me if I am wrong.. Are you saying I can use the inspect
> method to get the value of the aliased "total" attribute ?
>
No
> I don't think you meant that, but just confirming..
>
> If not, how else would I be able to get the value of total as a count of
> all users residing in each area of a city?
>
users = User.select('area, count(area) as
total').group('area').order('total
DESC').limit(30)
users[0].total
Fred
> I found an alternative with calling count towards the end of a Rails
> query, like this:-
>
> User.select(area, count(area) as total).group('area').count
>
> But I am not too sure how active record is taking count into
> consideration wrt the above case, and it would be more difficult for me
> to use it in complex queries without getting the basic understanding wrt
> 'count' in the above context..
>
> Your inputs on this..?
>
> Thanks..
>
> --
> Posted viahttp://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.