我有一个使用rails的问题
如何使用rails
执行此代码 select * from policy_vehicles where policy_id
IN ( SELECT id FROM policies WHERE
client_id IN (SELECT id FROM clients raz_soc = ?) )
谢谢,我将不胜感激
答案 0 :(得分:1)
.map(&:id)使用ActiveRecord where方法。您只需为SQL IN子句传入一组值。
PolicyVehicles.where(:column_a => value_a, :column_b => value_b)
所以
PolicyVehicles.where(:client_id => Client.where(:column => :value).map(&:id) )