Question

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])
Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top