[Ar] How To Query Related Model ?

Hi,

I have 3 model :


User 

   $id

   $name 


Car 

  $id 

  $name 


Transaction 

  $id 

  $user (belong to user)

  $car (has many car) 



I want to get list of user who buy the car with name X

I did sql query like

select user., transaction. from transaction, user, car where car.name = ‘X’ and transaction.car_id = car.id and user.id = transaction.user_id ;

But how to convert that query into ActiveRecord ?

you’d better check this topic :wink: