我怎样才能做多个条件?

时间:2013-10-02 18:08:20

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-3.1

我有一个使用rails的问题

如何使用rails

执行此代码
 select * from policy_vehicles where policy_id
    IN ( SELECT id FROM policies WHERE
    client_id IN (SELECT id FROM clients raz_soc = ?) )

谢谢,我将不胜感激

1 个答案:

答案 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) )