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

The Archive Base Latest Questions

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

I have the following relations: User –has many–> Reminders –has many–> Payments I get

  • 0

I have the following relations:
User --has many--> Reminders --has many--> Payments

I get all the payments of a user as

payments = User.reminders.collect{|reminder| reminder.payments.between(from_date, to_date)}.flatten

and then

data = payments.select("SUM(amount) as total_payment, MONTH(payment_date) as month, YEAR(payment_date) as year").group("MONTH(payment_date), YEAR(payment_date)").map{|payment| [payment.total_payment, "#{payment.month}/#{payment.year}"]}

I was trying to run the above select and group by query on a dataset which failed with the following exception:

ArgumentError: wrong number of arguments (1 for 0)
    from (irb):162:in `select'

The above query runs fine on Payments.where(”) but fails on Payments.all or the dataset which I have obtained above.
On debugging I found that Payments.where(”) is an ActiveRecord::Relation object whereas Payment.all is an Array.

An explanation would help me understand the concept and which way should I take. I don’t want to run that group by query for each reminder.payments individually and then sum it up.

  • 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-22T16:03:57+00:00Added an answer on May 22, 2026 at 4:03 pm

    You’ve got an array of Payment objects at that point, rather than a Relation, which represents a query that hasn’t been run yet. There’s two ways to approach this problem. The first would be to build payments as a relation rather than an array. I would do this by adding a has_many :through relationship between Users and Payments.

    class User < ActiveRecord::Base
      has_many :reminders
      has_many :payments, :through => :reminders
    end
    
    payments = user.payments.between(from_date, to_date)
    data = payments.select....
    

    The other way to do it would be to just pass the ids from your array to a where clause:

    payments = user.reminders.collect {...}.flatten
    data = Payment.where('id in (?)', payments).select...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use CakePHP 1.2.6 and have the following relations: Showcase HABTM User belongsTo Galleryitem
if a have a query like following = Relations.objects.filter(initiated_by = request.user) in which i'm
I have a graph of components and relations between them. User start navigation with
I have 2 models, User and Stash . A User has many stashes, and
I have the following relations: User hasMany UserNotification Notification hasMany UserNotification UserNotification belongsTo User
I have a Database that has the following relations: Transaction->Purchase->Item->Schedule Transaction - self explanitory
I am trying to get a One-To-Many relation working. I have the following mappings:
I have following models and relations between them: App has_many :subscriptions has_many :users, through:
I have the following relation in my model: A user can have several consumers
I have the following two entities: @Entity class Relation{ @ManyToOne private User user; //some

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.