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

  • SEARCH
  • Home
  • 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 6170085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:58:11+00:00 2026-05-23T22:58:11+00:00

source: has_many comments comments: has_many training_comments @negative_comments = Source.joins(:comments => [:training_comments]).where(training_comments.category_id = ? and

  • 0

source: has_many comments

comments: has_many training_comments

@negative_comments = Source.joins(:comments => [:training_comments]).where("training_comments.category_id = ? and comments.spam = ?", 2, false).select("sources.*, count(comments.id) as ncount").group("comments.source_id")

I want to list sources with their negative comments count but i am loosing sources which don’t have negative_comments(training_entries.category_id = 2). I tried everything to achieve this. I tried left join, i tried ifnull but none of them worked. Any help will be really really appreciated..

What i’m trying to do

Sources Count

source1 5

source2 0

source3 13

what i’m getting is

Sources Count

source1 5

source3 13

Sources table

id: integer
name: string

Comments table

id: integer
source_id: integer
spam: boolean

Training_comments table

id: integer
comment_id: integer
category_id: integer
  • 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-23T22:58:13+00:00Added an answer on May 23, 2026 at 10:58 pm

    You’re getting a zero because the standard JOIN doesn’t produce anything when there is no match. You need to get a LEFT OUTER JOIN past ActiveRecord; something like this:

    joins('LEFT OUTER JOIN comments ON comments.source_id = sources.id')
    

    AFAIK, you have to drop down to SQL to get a LEFT OUTER JOIN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My group has a source analysis tool that enforces certain styles that we have
I've just upgraded some old Java source which has been running on a Sun
I'm developing a Java application using Eclipse. My project has two source directories that
Java has some very good open source static analysis tools such as FindBugs ,
My office has a central Source Safe 2005 install that we use for source
Our company has a policy imposing the requirement of keeping source code in a
Has anyone used Mono, the open source .NET implementation on a large or medium
I'm trying to locate an open source business rules engine that has a decent
I want to process each source code file after it has been preprocessed: myprocess
Parser Error Message: The entry 'SiteSqlServer' has already been added. Source Error: Line 23:

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.