我有这个Rails 3.1 ActiveRecord查询:
Show.where('event_id = ? AND id not in (?)', params[:event_id], @dog.show_entries.map(&:show_id).join(','))
@dog.show_entries.count == 1
时工作正常。如果它有更多我生成SQL的问题,那就是:
SELECT "shows".* FROM "shows" WHERE (event_id = 1 AND id not in ('2,1')) ORDER BY date ASC
如何阻止它将2,1
括在引号中?
答案 0 :(得分:2)
放弃join(',')
:
Show.where('event_id = ? AND id not in (?)', params[:event_id],
@dog.show_entries.map(&:show_id))