我想执行一个 ActiveRecord 查询,该查询返回除具有特定 ID 的记录之外的所有记录。我想排除的 id 存储在一个数组中。所以:
ids_to_exclude = [1,2,3]
array_without_excluded_ids = Item. ???
我不确定如何完成第二行。
背景:我已经尝试过的:
我不确定背景是否必要,但我已经尝试过 .find 和 .where 的各种组合。例如:
array_without_excluded_ids = Item.find(:all, :conditions => { "id not IN (?)", ids_to_exclude })
array_without_excluded_ids = Item.where( "items.id not IN ?", ids_to_exclude)
这些都失败了。 这个技巧可能在正确的轨道上,但我没有成功地适应它。任何帮助将不胜感激。