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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:33:45+00:00 2026-06-10T00:33:45+00:00

I am getting missing FROM clause error (shown below) I want to find the

  • 0

I am getting missing FROM clause error (shown below)

I want to find the entries whose associated reports’ city is the same as the users’ city, thus only showing relavant entries to users. So, if a user belongs to a city that a report does, the user should be shown the entries from that report.

I tried a few things, one being this scope in the Entry model:

scope :report_in_city, lambda { |user| joins(:report).where("report.city_id = ?", user.city_id) }

And if I call Entry.report_in_city(user)

I get this error:

SELECT "entries".* FROM "entries" INNER JOIN "reports" ON "reports"."id" = "entries"."report_id" WHERE (report.city_id = 1)
ActiveRecord::StatementInvalid: PG::Error: ERROR:  missing FROM-clause entry for table "report"
LINE 1: ... ON "reports"."id" = "entries"."report_id" WHERE (report.cit...
                                                             ^
: SELECT "entries".* FROM "entries" INNER JOIN "reports" ON "reports"."id" = "entries"."report_id" WHERE (report.city_id = 1)

I have a few models set up like this:

class Report
belongs_to user
belongs_to city
has_many entries

class Entry 
belongs_to report

class User 
has_many reports
belongs_to city

class City
has_many users
has_many reports

I am new to sql and would appreciate any advice on this query!

  • 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-10T00:33:46+00:00Added an answer on June 10, 2026 at 12:33 am

    Since that string condition "report.city_id = ?" goes into the SQL, you have to use the table names. Rails is cute about going back and forth between plural and singular, but SQL only knows the table name reports. You can see that in the generated SQL like ON "reports"."id" = "entries"."report_id". The table name is plural.

    Try this:

    "reports.city_id = ?"
    

    or the Rails way:

    joins(:report).where(:report => { :city_id => user.city_id })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a missing template error after I try rendering a partial from a
For the following make file copied below, I am getting the missing separator error.
I'm getting the missing action in controller from CakePHP, but the action home is
I'm getting odd behavior (it generates only missing values) from the following loop -
I'm getting an error message of ORA-00936: missing expression at the very start of
I am not getting any error message in browser due to curly brace missing
What am I missing here? This is the error I am getting... error: type
After upgrading from Cake 1.3 to 2.0 I I'm getting missing table errors for
I am getting ORA-00905: missing keyword error when trying to run the following query
Possible Duplicate: R.java Missing in Android Project in NetBeans In Android I am Getting

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.