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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:31:46+00:00 2026-05-23T11:31:46+00:00

This question is fairly similar to [1], except that I’m using Rails 2.3.5 (yes,

  • 0

This question is fairly similar to [1], except that I’m using Rails 2.3.5 (yes, old) and a complete newb at RoR. I have two models, Configfile and Signoff.

I want to find all Configfiles where the number of signoffs is < 2. Of course, I could do this by filtering the array manually, but this database is big and it’s fairly slow.

class Configfile < ActiveRecord::Base
  belongs_to :computer
  has_many :signoffs,
           :dependent => :destroy
end

and

class Signoff < ActiveRecord::Base
  belongs_to :configfile
end

This seems like something that should be fairly easy to do in Rails, but I can’t figure it out.
My query looks like this so far, and I haven’t gotten anything that works for limiting it by the number of signoffs.

configs = c.configfiles.find(:all,
                             :include => :signoffs,
                             :order => 'filename')

[1] Rails 3 query on condition of an association's count

  • 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-23T11:31:46+00:00Added an answer on May 23, 2026 at 11:31 am
    Configfile.find(:all, :group=>"configfile_id", :joins=>:signoffs, :having=>"count(*) &lt 2")
    

    Which should give you the same as the equivalent rails3:

    Configfile.joins(:signoffs").group("configfiles.id").having("count_all < 2").count(:all)
    

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

Sidebar

Related Questions

First off, fairly new to JS but getting better :-) This question is similar
I've a question that should be fairly simple, but I have yet to find
This question is fairly fundamental.I gave a simple and straighfoward test on my cygwin:
This question may sound fairly elementary, but this is a debate I had with
I'm not a regular C++er, so this question might be fairly trivial: Can anybody
First of all, I'm fairly new to Java, so sorry if this question is
This is a fairly basic question, which for some reason, a proper solution escapes
This seems like a fairly obvious question, but I haven't been able to think
I think this is a fairly common question: how to put my business logic
fairly simple question and I haven't seen anything asked with this exact scenario laid

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.