1
对于简单的查询,或查询中的ActiveRecord可能是这样的:的ActiveRecord或查询在阿雷尔
Model.where({:category => "XYZ", :item_id => some_ids})
=>
table = Model.arel_table
Model.where(table[:category].eq("XYZ").or(table[:item_id].in(some_ids)))
结果是不是很紧凑,清晰。如果您有更复杂的查询, 在Arel中编写以下ActiveRecord查询是否可行并且有用?
Model.where(["(item_id = ? AND item_type = 'ABC') OR
(item_id IN (?) AND item_type = 'XYZ')",id,more_ids]).
order("created_at DESC")
看看https://github.com/oelmekki/activerecord_any_of – apneadiving