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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:12:06+00:00 2026-05-23T04:12:06+00:00

I am putting together a report that shows statistical information about products for a

  • 0

I am putting together a report that shows statistical information about products for a company that owns those products. This report, in the form I need, contains as many as 150 ‘counts’, because we are filling the table with the counts for 12 product types against 15 different statistical categories.

Here’s the set up of the models. I’m afraid it’s a little complicated!

Company is the entity accessing the report.

Company has many Products through Matchings; and  
Product has many Companies through Matchings.

Matching belongs_to Order.

Example report:
___________|_Available/Active/Light   Available/Active/Heavy   (+12 columns)__
Perishable |
Intangible |
(+10 rows) |

The product types are in the Product table (they run down the left side of the report).
The categories across the top of the report are combinations of three criteria: two from Product and one from Order.

Example – for one cell in the Perishable row, show me how many matchings exist for whom the order type is ‘active’, the product’s weight is ‘light’ and the product status is ‘available’.

On its own the above query is not too bad, but if I keep going like this I’m going to have ~170 queries for this report – both an inelegant and highly impractical solution. Is there a magic ActiveRecord way to deal with this scenario?

  • 1 1 Answer
  • 1 View
  • 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-23T04:12:07+00:00Added an answer on May 23, 2026 at 4:12 am

    You could always create a background job to run regularly and pre-cache the results, or pre-generate the entire report. This would free your users from having to sit and wait for 170 queries to run, and I assume it would be acceptable to have slightly stale results.

    As for the elegance and practicality of it, the only magic you could use is SQL. Your object model wasn’t built for reporting, don’t feel bad about using a tool that was.

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

Sidebar

Related Questions

I am having trouble putting together a script that lists various business contact information.
I have a large database and am putting together a report of the data.
I putting together a page that will display a set of stored values. I
I am putting together a fairly simple web app that uses user inputted data
I am putting together a technical analysis library that I hope others may use
I'm putting together a simple web page that presents the user with a jQuery
I'm putting together this basic script for a site: http://jsfiddle.net/mcgarriers/rVPnu/2/ It works great when
So I'm putting together a little code metrics report based off of usage data
I'm putting together a simple drop down that contains nested ul's. I want it
I am currently putting together some jQuery that will activate slideDown() when an element

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.