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
I am assuming that you mean this:
Car has
radio_id, User hascar_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:
if there is a category column on the radio, the following would work.
For Rails Version >= 4: