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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:11:21+00:00 2026-06-13T17:11:21+00:00

I have a Payment Model which is polymorphic on activities class Payment belongs_to :activity,

  • 0

I have a Payment Model which is polymorphic on activities

class Payment
  belongs_to :activity, polymorphic: true
end

one of the activities is referrals.

class Referral
  has_many :payments, :as => :activity

  def self.unpaid
    where(payments.count == 0)
  end
end

I want to create a class method so I can get all of the referrals which are unpaid. I was using this approach above, but getting a undefined_method error on payments.
Referral.first.payments.count works fine.

what am I missing here?

  • 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-13T17:11:23+00:00Added an answer on June 13, 2026 at 5:11 pm

    It sounds to me what you’re looking for are ActiveRecord Scopes. Using a scope, you’d do something like this:

    class Referral
      has_many :payments, :as => :activity
    
      scope :unpaid, includes(:payments).where('payments.id is null')
    end
    

    This will perform a join on payments, and then the condition will find all columns that have no payments.id (in other words, with no payments). Then you could do Referral.unpaid.all, and see all referrals where there are no joined payments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the following model: payment.rb: class Payment < ActiveRecord::Base has_many :currencies default_scope :include
I have an Order model, which has_many payments and a checkout Controller. The Controller
I have a payment_types table in which you can enter different payment types such
using ASP.NET MVC, I have a Model, to which I'm attaching attributes so that
I have the below db model: from datetime import datetime class TermPayment(models.Model): # I
I have created an OrderFormViewModel which looks something like public class OrderFormViewModel { public
I have a data model as follows: A Customer has Products and Payment Methods.
I have a product and payment_notification model with the following association class Product <
I have an existing form which is tied to a model named 'Order', but
I currently have a small HTML form for a third party payment service, which

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.