Saturday, November 26, 2011

[Rails] Re: Converting SQL query to Rails query for a non model attribute

Frederick Cheung wrote in post #1033717:
> On Nov 25, 3:05pm, "Mohnish J." <li...@ruby-forum.com> wrote:
>> > from the actual columns on the table. You can still call total (in
>> > this case) to get that value.
>>
>> Hi Fred...
>>
>> By print, I basically am trying to get the output on the Rails console
>> for a "non model attribute" in particular.. which I'm unable to do ,
>> yet..
>
> like I said, just call the method. Just because it doesn't show up in
> the output from inspect doesn't mean it's not there.
>
> Fred

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 ?

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?

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 via http://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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate