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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:02:02+00:00 2026-06-10T05:02:02+00:00

I am building an app for this scuba school that has muiltiple locations and

  • 0

I am building an app for this scuba school that has muiltiple locations and muiltiple courses at each school. I am trying to make it so users can find all the courses taught by a particular instructor, at a particular school (oh boy). The schema is as follows:

 create_table "courses", :force => true do |t|
    t.string   "course_name"
    t.integer  "course_number"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.integer  "teacher_id"
    t.integer  "school_id"
  end

  create_table "teachers", :force => true do |t|
    t.string   "fname"
    t.string   "lname"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.integer  "school_id"
  end

I have the following relationships set up:

courses belong_to school
courses belong_to teacher

teacher belong_to school

school has_many courses
school has_many teachers

I have no clue how to do this, but this is my (idiotic) attempt:

#I need to match these queries where course.teacher_id is equal to teacher.id
teachers = Teacher.where('fname ILIKE ? OR lname ILIKE ?', params[:fname], params[:lname])
courses = Course.where('school_id = ?', params[:id])

#now to join the above queries
courses_offered_by_searched_teacher_at_specified_school = courses.joins(teachers)

I hope you are able to follow what I am trying to do. Any and all help would be appreciated.

  • 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-10T05:02:04+00:00Added an answer on June 10, 2026 at 5:02 am

    This is how you are supposed to use joins:

    Course.joins(:teacher).where('(teachers.fname ILIKE ? OR teachers.lname ILIKE ?) AND courses.school_id = ?', params[:fname], params[:lname], params[:id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building this app and I can't make it work. Here is the
I am building an App that fetches all entries a user has made this
Im building an app which uses Sqlite DB. Users can enter their information into
I've been building this little app that runs on our work computers. It just
This is the case I am building app that will be localized via strings
I'm building an app that needs to hide consecutive rows. Currently I'm using this:
I am building an app that has multiple useful functionalities. One activity uses google
I've building a app right now that I'm trying to keep properly decoupled from
I'm building an app that takes a photo and then e-mails it. For this
I am building a web-app that will users mark-up images by drawing on it

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.