简体   繁体   中英

Ruby Rails Query In conditional

I have this query that works but I would like to expand it so that I can check for multiple ids such that I pass in a vector of ids. [1,2,3,5] etc... I have tried using SQL IN with no luck.

EventType.find(3).events.all(:include => {:sheet => :rink}, :conditions => ["rinks.id = ?", 2])

You were on the right track with IN . Here's syntax that will work in Rails 3+:

EventType.find(3).events.where("id IN (?)", [1,2,3]).include(:sheet => :rink)

Improvement from a comment removes SQL entirely:

EventType.find(3).events.where(:id => [1,2,3]).include(:sheet => :rink)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM