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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:59:58+00:00 2026-06-04T10:59:58+00:00

My goal is to export votes, per model object for a given collection. In

  • 0

My goal is to export votes, per model object for a given collection. In this example I use .all, but in the wild, it will be a .where that yields the large set. I have the following query that I am concerned about:

Model.all.each{|x|puts x.votes.count}.explain

   (0.4ms)  SELECT COUNT(*) FROM `votes` WHERE `votes`.`entry_id` = 1
0
   (0.3ms)  SELECT COUNT(*) FROM `votes` WHERE `votes`.`entry_id` = 2
0
   (0.4ms)  SELECT COUNT(*) FROM `votes` WHERE `votes`.`entry_id` = 3
1
   (0.3ms)  SELECT COUNT(*) FROM `votes` WHERE `votes`.`entry_id` = 4
0
   (0.2ms)  SELECT COUNT(*) FROM `votes` WHERE `votes`.`entry_id` = 5
0

Individually count is very quick, but I don’t feel comfortable calling All, especially when I have a collection in the thousands or millions. Is there a way to count records as a batch opporation?

  • 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-06-04T11:00:00+00:00Added an answer on June 4, 2026 at 11:00 am

    Not sure what you mean by “All”, but do the same thing, only try using GROUP BY the ID and the COUNT function. Something like this:

    SELECT COUNT(*) FROM Votes GROUP BY entry_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The ultimate goal is to use JSFL to export a 2D skeleton from Flash.
Goal To use a CREATE TYPE statement in HSQLDB 2.0.0 to create a user-defined
Goal: json_encode a PHP object that has private properties Send the encoded object as
My goal is to generate a html file with tables and export them into
How can I convert/export binary data (for example binary files like excel- or word-documents)
I don't know the best way to title this question but am trying to
Is there a standard site structure format? The use of this would be for
EMF has support for XSD through Ecore to XSD import export capability, but I
I'm trying to use jQuery-jsonp plugin with jQuery Deferred Objects but I'm having no
Using appcfg.py it's quite easy to import export the datastore. But what about the

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.