Now I figured out what is the error...
I dont know why... But rails changed the column name where you count froum
comments_count to count_all... And you refer it on your order by statement
using the alias you choose...
I hope somone more experienced on rails help you fix it, but for now... U
could do 2 fix...

You can call the alias rails choose (count_all) on your order statement
(ugly way to solve)
Or you can call for count(*) without alias on your order statement (more
practiced by dba... Less ugly to solve)
Em 24/07/2013 07:40, "Yaw Boakye elGran" <yawboaky...@gmail.com> escreveu:

> Error message:
>
> PG::Error: ERROR:  column "comments_count" does not exist
> LINE 1: ...l, titles.created_at, titles.updated_at  ORDER BY comments_c...
>                                                              ^
> : SELECT COUNT(*) AS count_all, titles.id, titles.title, 
> titles.submitter_name, titles.submitter_email, titles.created_at, 
> titles.updated_at AS 
> titles_id_titles_title_titles_submitter_name_titles_submitter_e FROM "titles" 
> INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY 
> titles.id, titles.title, titles.submitter_name, titles.submitter_email, 
> titles.created_at, titles.updated_at  ORDER BY comments_count DESC
>
>
>
>
> On Wed, Jul 24, 2013 at 10:38 AM, Yaw Boakye elGran <yawboaky...@gmail.com
> > wrote:
>
>> @Carlos this query still throws an exception:
>>
>> def self.order_by_number_of_comments_descending
>>         select('titles.id, titles.title, titles.submitter_name,
>> titles.submitter_email, titles.created_at, titles.updated_at, count(
>> comments.id) AS comments_count').
>>         joins(:comments).
>>         group('titles.id, titles.title, titles.submitter_name,
>> titles.submitter_email, titles.created_at, titles.updated_at').
>>         order('comments_count DESC')
>>     end
>>
>>
>>
>> still complaining about not finding comments_count :/
>>
>> I'm using *PostgreSQL 9.1.5*
>>
>>
>> On Wed, Jul 24, 2013 at 10:32 AM, Yaw Boakye elGran <
>> yawboaky...@gmail.com> wrote:
>>
>>> I think so, sorry for the misinformation. Thanks for the correction :)
>>>
>>>
>>>
>>>
>>> On Wed, Jul 24, 2013 at 12:36 AM, Scott Ribe <
>>> scott_r...@elevated-dev.com> wrote:
>>>
>>>> On Jul 23, 2013, at 6:28 PM, Yaw Boakye elGran <yawboaky...@gmail.com>
>>>> wrote:
>>>>
>>>> >       • During grouping, the normal SQL requirement is to group on a
>>>> column that is on both tables. As far as I know, grouping can't be done on
>>>> two tables when they don't a common column. In your group call, only
>>>> titles.id would be useful. The rest won't
>>>>
>>>> You seem to be confusing the grouping with the join condition. The join
>>>> requires 1 (usually, sometimes more) column common to both tables. The
>>>> grouping must include all columns not used in the aggregate function.
>>>>
>>>>
>>>> --
>>>> Scott Ribe
>>>> scott_r...@elevated-dev.com
>>>> http://www.elevated-dev.com/
>>>> (303) 722-0567 voice
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Ruby on Rails: Talk" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to rubyonrails-talk+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/rubyonrails-talk/4F79E8C6-3BB4-4FE0-A64C-7B55C92DF4E8%40elevated-dev.com
>>>> .
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> visit my blog @ yawboakye.blogspot.com     | call me on +233242057831or
>>> +233273201210
>>>
>>
>>
>>
>> --
>> visit my blog @ yawboakye.blogspot.com     | call me on +233242057831 or
>> +233273201210
>>
>
>
>
> --
> visit my blog @ yawboakye.blogspot.com     | call me on +233242057831 or
> +233273201210
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDu_wG%2BD3QsVQv0YoRMLdJwhT29kMT0znaFTp0vfrj0aXQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXt%2BAw-Uks%2B-_bjOCzV5BW6ASAHK%3Dz6FKECSYNcuge20KQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to