我正在尝试编写这个将成为WHERE IN子句的AR查询:
User.include(:country).where(:country_id, @countries).order(:...).limit(10)
其中@countries可以是AR查询的任何结果:
@countries = Country.find(...)
我怎样才能这样做:
WHERE country_id in (1,2,3,4,5)
答案 0 :(得分:1)
User.include(:country).where('country_id IN (?)', @countries.map(&:id))...