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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:58:56+00:00 2026-06-08T11:58:56+00:00

I have tried everything i thought would work for this and am turning up

  • 0

I have tried everything i thought would work for this and am turning up nothing.

in rails 3, I need to find all users with a cd player in their car. A car has one user and one radio, and a user belongs to a car, and a radio has many cars.

I am stumbling on how I would perform this search via a scope in the user model.

class User  
  belongs_to :car

class Car  
  belongs_to radio
  has_one :user, :dependent => destroy

class Radio  
  has_many :cars
  • 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-08T11:58:58+00:00Added an answer on June 8, 2026 at 11:58 am

    I am assuming that you mean this:
    Car has radio_id, User has car_id,
    since a radio has many cars and car has one user. The table with the foreign key always is on the belongs_to end of the relationship.

    Without really knowing the structure you’re looking for, something like the following should work:

    scope :with_cd_player, joins(:cars).where('cars.radio_id is not null')
    

    if there is a category column on the radio, the following would work.

    scope :with_cd_player, joins(:car => :radio).where('cars.radio_id is not null').where("radios.category = 'cd_player'")
    

    For Rails Version >= 4:

    scope :with_cd_player, -> { joins(:cars).where.not(cars: { radio_id: nil }) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Cant get this script to work with my menu really have tried everything any
I have tried everything in the book and EVERYTHING I could find on how
This might get a little confusing as I have tried everything to make this
Hi I have tried for 2 hours everything that I could find on the
I have been at this for several days now and tried all sorts of
I've tried everything Google and StackOverflow have recommended (that I could find) including using
I have tried everything, searched the net for two hours or even more and
Having an issue here that I have tried everything I can think of but
I'm having trouble making python print out texts properly aligned. I have tried everything
I have nearly tried everything but cannot figure out what is wrong. 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.