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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:41:43+00:00 2026-06-11T22:41:43+00:00

I have a Post model that has an associated Comment model. Each comment has

  • 0

I have a Post model that has an associated Comment model. Each comment has a user_id associated with a User model…all very standard stuff.

Essentially, when I fo a find query on all the Posts I’m interested in, I am looking for a way to efficiently get the number of unique user_id’s that have commented on each Post.

  • 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-11T22:41:44+00:00Added an answer on June 11, 2026 at 10:41 pm

    Have you used counterCache? That will probably get you where you need to be. You will also want to combine that with some fancy conditions on counterScope. This will allow you to save the number of commenters when a record is saved/updated, instead of on the fly; resulting in a faster page and a better user experience.

    Now, this alone may not get you to the final solution. Consider using a combination of counterCache/counterScope and virtualFields to pull the data and update that way.

    Read about counterCache in the Book

    • 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 User model and Post model. Post model contains field user_id
Say you have a Post model that has a :title , :author , :content
I have a post controller that has many comments. The post model has a
I have a Post model that has a polymorphic association with a Vote model:
I have a Post model object that has reference to a parent object. The
I have comment model that references (foreign key) a post model and there is
I have 3 model, User, Post, Comment with definition like below class Post <
I have a model that has ratings in it for an post. I want
I have a post model that has many tags through taggings. let's say: @posts
I have a Post model that has a datetime.date field for posted_date . I

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.