【发布时间】:2012-02-22 19:07:16
【问题描述】:
所以基本上我有这个范围(sql):
scope.to_sql
=> "SELECT \"offers\".* FROM \"offers\" INNER JOIN \"cities_offers\" ON \"offers\".\"id\" = \"cities_offers\".\"offer_id\" WHERE \"cities_offers\".\"city_id\" = 2 AND \"offers\".\"category_id\" IN (2) AND (offers.category_id is NOT NULL) ORDER BY offers.discount desc LIMIT 25 OFFSET 0"
不知何故,上述查询的记录顺序与没有 LIMIT 和 OFFSET 的相同查询不同:
scope[6]
=> #<Offer id: 8629 ...
scope.except(:offset, :limit)[6]
=> #<Offer id: 8729 ...
8629 和 8729 记录具有相同的 discount 值(我排序的属性)。
您能否建议在这种情况下是否可以保持相同的记录排序?
【问题讨论】:
标签: sql ruby-on-rails postgresql activerecord sql-order-by