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 6018917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:20:38+00:00 2026-05-23T03:20:38+00:00

For example, say I have something like BlogCategory which has a HABTM with BlogPost,

  • 0

For example, say I have something like BlogCategory which has a HABTM with BlogPost, and I want to select only the BlogCategories that have actually been used in a BlogPost

named_scope :published, {
  :include    => :blog_posts,
  :select     => 'blog_categories.*, count(blog_posts.id) as post_count',
  :group      => 'blog_categories.id having post_count > 0',
  :conditions => 'blog_posts.published = 1',
}

Problem I’m having is that the :select part of this seems to be getting completely ignored by rails, so the count field doesn’t get put into the query, and I end up with the error “Unknown column ‘post_count’ in ‘having clause'”

  • 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-23T03:20:39+00:00Added an answer on May 23, 2026 at 3:20 am

    I don’t know why it doesn’t recognize post_count but it should work with:

      :group      => 'blog_categories.id having count(blog_posts.id) > 0',
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have something like this (this is only an example, actual request
Say I have something like -- this is just an example mind you. class
For example lets say I have a JSON object that contains states and cities.
To use as an example: lets say that I have 2 EditText s and
Say I have a class ObjectA (a view controller for example), that does this
Is there something like Python with context manager in Java? For example say I
I have something like this: Create Procedure GetStockNumber @Barcode int As Select CodStock from
lets say I have something like this: class Program { static void Main(string[] args)
For example, say I have an ArrayList that could contain the following values: x
Let's say I want to have a function which reads data from the SerialPort

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.