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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:46:42+00:00 2026-05-12T22:46:42+00:00

I have a Proposal model and a Signature model. Proposal has many signatures and

  • 0

I have a Proposal model and a Signature model.

Proposal has many signatures and Signature belongs to proposal

My relationships work fine when I select a single Proposal, but when I do a Proposal.search and return multiple proposals, I can’t access signatures.

I want to sort my proposals by signatures count, so I tried this:

Proposal.find(:all, :limit => 3, :include => [:signatures])

Now when I debug(@proposals) I do see the corresponding signatures. How do I access them and write an :order => signatures.count ?

I’m not very familiar with includes / joins …so let me know if I’m going about this the wrong way. Thanks.

  • 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-12T22:46:43+00:00Added an answer on May 12, 2026 at 10:46 pm

    :include is used when you will need to access the signatures later. If all you need is the count of associated signatures for sorting, then you do not need :include.

    I don’t especially like the following, but it seems to work:

    Proposal.find(:all,
                  :limit => 3,
                  :joins => :signatures,
                  :group => 'proposals.id',
                  :order => 'count(proposals.id) desc')
    

    First, the :joins parameter means that for each Proposal record you will get another row in the output for each associated Signature. The :group parameter combines those rows into one, but only after the :order parameter sorts based on the number of rows for each proposal.id (and hence number of signatures).

    I suspect there is a better way, but this seems to work.

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

Sidebar

Related Questions

The functionality I'm looking for: I have a form that will search my 'Proposal'
I have an interesting content layout proposal but I'm having difficulty figuring out how
I noticed for...of loops were added to the ECMAScript-6 proposal, but have never heard
I have an object Proposal which has a property called CurrentAgency of Agency which
I have class with many variables. Few of them are File types class Proposal
I have a model with a integer field wich will increment on user click,
I have a C#/WPF application with a tabbed interface that has been behaving strangely.
Friends, I am new to lucene full text search. i have developed page with
I have two tables client and proposal in database, db.client = > id,name db.proposal
I have a SQL Server 2008 db. It contains some great test data...a proposal

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.