Question

I have a question using rails

How can i do this code using rails

 select * from policy_vehicles where policy_id
    IN ( SELECT id FROM policies WHERE
    client_id IN (SELECT id FROM clients raz_soc = ?) )

Thanks i will appreciate help

Was it helpful?

Solution

.map(&:id)Use the ActiveRecord where method. You can just pass in an array of values for your SQL IN clause.

PolicyVehicles.where(:column_a => value_a, :column_b => value_b)

So

PolicyVehicles.where(:client_id => Client.where(:column => :value).map(&:id) )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top