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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:59:50+00:00 2026-05-17T19:59:50+00:00

I have the following model, Purchase, on my Rails app: class Purchase < ActiveRecord::Base

  • 0

I have the following model, Purchase, on my Rails app:

class Purchase < ActiveRecord::Base
  [...]
  belongs_to :payment, :validate => true
  belongs_to :day, :foreign_key => :day_day, :primary_key => :day, 
    :counter_cache => true
  [...]
end

And I have the Day model:

class Day < ActiveRecord::Base
  [...]
  has_many :purchases, :foreign_key => :day_day, :primary_key => :day
  [...]
end

I’d like to create an association between the day and the payments occurred during that day through the Purchase model. Is it possible?

Thanks a lot!

  • 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-17T19:59:50+00:00Added an answer on May 17, 2026 at 7:59 pm

    It might help if you can give a little more detail on why your relationships are set up the way they are.

    My first question is what does a Day object consist of? Could it be replaced by having a “purchased_on” attribute on the Purchase model?
    If so, this can be done pretty easily through a scope on Purchase.

    Second, the way you have it now a single Payment has many Purchases. Is this really what you mean, or do you actually want a Purchase that has many Payments?

    Let me know, and I’ll see if we can get something worked out for you.

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

Sidebar

Related Questions

I have the following model in Django: class Bout (models.Model): fighter_1 = models.ForeignKey(Fighter, related_name=bout_fighter_1)
I have the following model structure below: class Master(models.Model): name = models.CharField(max_length=50) mounting_height =
How would you implement this ? I have the following model : class Something
I have the following django model (mapped to table 'A'): class A(models.Model): name =
I have the following model: model rank(Models.model): username = models.CharField(max_length=200, default=0) points = models.IntegerField(default=0)
I have the following model and url routes. There is one Post model that
Can someone please clarify the following; if a have the following model; presentation-->slide-->video where
I'm getting some trouble binding a date from QueryString : I have the following
I'm pretty confused how to validate boolean values in Rspec and Rails. I understand
I'm using Doctrine 1.2 as my ORM for a Zend Framework Project. I have

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.