Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:59:22+00:00 2026-05-27T04:59:22+00:00

I have a model Issue. Issues have Comments and Votes through join models. In

  • 0

I have a model Issue. Issues have Comments and Votes through join models. In my issues#index view, I would like to be able to sort the query results by the number of comments and votes as so:

@issues = Issue.limit(10).find(:all, :order => "COMMENT_COUNT DESC")

However if I try something like:

@issues = Issue.limit(10).find(:all, :order => "issue.comments.count DESC")

it doesn’t work. I can probably add a comment and vote count to the issue model…but i’m not sure what the best way to do that is and I don’t even think it is the best way.

How should I be doing that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:59:23+00:00Added an answer on May 27, 2026 at 4:59 am

    It’s a little bit more involved than this. This requires a bit more sql. You have to include the comments table in the query for your issues. You then have to group the results by the Issue id to get the count of comments per issue.

    Something like this should work:

    @issues = Issue.find(:all, :order => "count(comments.id) DESC"), :joins =>"inner join comments on comments.issue_id = issues.id", :group =>"issues.id",:limit=>"10" )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some issues using has_one, through => model . The best is to
I have an Issue model and a Comment model. On the issue#show view, I
I am newbie at Django. I have model with a custom method. In view
I have a single text area input that I would like to get as
I have a model Issue and a nested Model Relationship In the issue.rb I
I have a MySQL database that is exhibiting behavior I would like to understand
I have model Foo which has field bar. The bar field should be unique,
I have model Article it has field title with some text that may contain
Lets say I have model inheritance set up in the way defined below. class
If I have Model.objects.all() I want to get only one object for any content_object=foo,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.