문제

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top