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

  • Home
  • SEARCH
  • 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 8392093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:25:53+00:00 2026-06-09T19:25:53+00:00

I think I’m getting this issue because my Child Class can belong to one

  • 0

I think I’m getting this issue because my Child Class can belong to one Parent or the other Parent but not both. Let me show you my code and then the error.

class Purchase < ActiveRecord::Base # my child class
  # columns = user_id, price_id and unit_price_id
  belongs_to :user
  belongs_to :price
  belongs_to :unit_price

  scope :today, lambda { joins(:unit_price, :price).
                             where(:price => { :date => Date.today },
                                   :unit_price => { :date => Date.today } ) }
  def total
    self.price.sum(:amount) + self.unit_price.sum(:amount)
  end
end

And than I try to do this in my view:

<%= number_to_currency(current_user.purchases.today.map(&:total)) %>

But this gives me the error:

PGError: ERROR:  missing FROM-clause entry for table "price"
LINE 1: ...s"."price_id" WHERE "purchases"."user_id" = 3 AND "price"."d...
                                                             ^
: SELECT "purchases".* FROM "purchases" INNER JOIN "unit_prices" 
ON "unit_prices"."id" = "purchases"."unit_price_id" 
INNER JOIN "prices" ON "prices"."id" = "purchases"."price_id" 
WHERE "purchases"."user_id" = 3 AND "price"."date" = '2012-08-16' 
AND "unit_price"."date" = '2012-08-16'

I really don’t know exactly what its saying here but have an idea which is that the price_id is nil. Is this correct? If so how do I fix this issue? Should I create two seperate purchase models called PricePurchase and UnitPricePurchase as a fix?

Let me know what you think.

Thank you.

  • 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-09T19:25:54+00:00Added an answer on June 9, 2026 at 7:25 pm

    Tables aren’t aliased and their names are in plural (prices, not price in WHERE), so perhaps this change would help:

    where(:prices => { :date => Date.today },
                                   :unit_prices => { :date => Date.today } ) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i think i have a little issue, but i'm not sure, because it's either
I think this has probably been asked, but after reading a lot, I'm not
I think I've seen this answer, but I can't remember where for certain. I'm
I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
I think that asking this might be kind of silly but I'm still wondering
I think this is specific to IE 6.0 but... In JavaScript I add a
Think this is my target key in registry: [HKEY_CURRENT_USER\System\Majid\0] GUID=hex:60,de,2a,56,51,b2,e0,11,80,01,44,45,53,54,00,00 as you can see
i think this is an easy one for you: I have a Controller in
think this should be an easy one... I want to get the currently selected

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.