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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:51:16+00:00 2026-06-17T11:51:16+00:00

Assuming, There are tables called User , and Community Community is created by a

  • 0

Assuming, There are tables called User, and Community

Community is created by a User, and it has user_id.
Community also has the number of Users who liked the community.

Let’s say

There are these communities. the number inside of () is the number of users who liked the community.

  • community A (17), Community Owner is user_id ‘2’
  • community B (35), Community Owner is user_id ‘1’
  • community C (8), Community Owner is user_id ‘2’

I’d like to get summarized number of Users who liked User ‘2’ his community.
It should be 25 (17 + 8), here.

How can I get this?

It should be something like this? cached_votes_up has the number of users who like the community.

@user = User.find(2)
@communities = Community.find(@user).
@user.summarized_number = @communities.cached_votes_up.count
@user.save
  • 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-17T11:51:17+00:00Added an answer on June 17, 2026 at 11:51 am

    You can use the ActiveRecord::Calculations#sum method:

    @user.summarized_number = Community.sum(:cached_votes_up, :conditions => ["user_id = ?", @user.id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have two tables: users and orders . A user has many orders,
Assuming that I had two Models called User and Comment And there is a
Assuming that there's a table called tree_node , that has the primary key called
I have two tables: regions <id> points <region_id, x, y> Assuming there are exactly
Assuming there are two tables A={a,b} and B={0,1,2}, which can be joined tableA tableB
Assuming I have two tables, users and audit, and the audit table is populated
Example scenario: TABLE_A contains a column called ID and also contains duplicate rows. There
Assuming there are 5 inputs in web form <input name='the_same[]' value='different' /> <input name='the_same[]'
Assuming there are buttons with all the letters from the alphabet set as Text.
Assuming there is a task (e.g. an image processing method with a lot math)

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.