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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:31:57+00:00 2026-05-22T11:31:57+00:00

This is almost answered in Difference Between find and Where with Relationships but not

  • 0

This is almost answered in Difference Between find and Where with Relationships but not quite. (Notice how I subtly changed the question title!)
I do the query

a = Libation.where("user_id = 1" )   # gets 10 records
b = a.sum("count * weight")          # Get right answer
c = Libation.where("user_id = 2" )   # gets 8 records
d = c.sum("count * weight")          # Get right answer

Now I do

e = Libation.all                # gets 18 records, good
f = e.sum("count * weight")     # BOOM! I get

NoMethodError (undefined method `+' for #<Libation:0x3b91e88>):

Nuts. I tried to find relevant docs, but found little. Or I am not looking in the right place.

  • 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-22T11:31:58+00:00Added an answer on May 22, 2026 at 11:31 am

    #where returns an ActiveRecord::Relation object, which you can them perform additional methods on (such as #sum). However, #all executes the query returns an array of results, so when you do e.sum(...) you’re trying to perform #sum on an Array object rather than an ActiveRecord::Relation object.

    You might try using #scoped instead:

    e = Libation.scoped
    f = e.sum("count * weight")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen the question almost answered on a number of threads, but not considering
This is almost certainly a very silly question, but for some reason I'm having
I am almost embarrassed to ask this question, but as a long time C
I'm almost positive this has been answered already; however, unable to find it since
I know this has prob been answered, but I've searched for almost an hour
I had asked a question about this earlier, but it didn't get answered right
this must have been asked and answered but couldn't find an answer. What I'd
I'm almost certain I know the answer to this question, but I'm hoping there's
Yes, I realize this question was asked and answered, but I have specific questions
Apologies, this is almost certainly a duplicate of this question but as that one

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.