更像是重写命令
Entity.associations.order("field ASC").reorder("other_field DESC")
# => result: GET ... order by other_filed DESC
是否可以覆盖范围选项?
Entity.associations.where("field = 1").where("field = 2")
# => GET ... where "field" = 1 and "field" = 2
# Desirable:
Entity.associations.where("field = 1").rescope(where("field = 2"))
# => GET ... where "field" = 2
P.S。
Rails 3
P.S.S 接受的答案对Rails4
有效答案 0 :(得分:2)
您可以使用unscope方法完全删除您所在的条件:
Entity.asscocations.where(field: 1).unscope(:where).where(field: 2)
或者只是从您的条件中删除特定字段:
Entity.asscocations.where(field: 1).unscope(where: :field).where(field: 2)