Commit 17ed24fda3d6c63c40960cb983c2795856ca5078
1 parent
145c6f16
Exists in
master
and in
21 other branches
Ensure can always sort on id
Showing
2 changed files
with
8 additions
and
1 deletions
Show diff stats
lib/searchkick/search.rb
... | ... | @@ -179,7 +179,7 @@ module Searchkick |
179 | 179 | # order |
180 | 180 | if options[:order] |
181 | 181 | order = options[:order].is_a?(Enumerable) ? options[:order] : {options[:order] => :asc} |
182 | - payload[:sort] = order | |
182 | + payload[:sort] = Hash[ order.map{|k, v| [k.to_s == "id" ? :_id : k, v] } ] | |
183 | 183 | end |
184 | 184 | |
185 | 185 | term_filters = | ... | ... |
test/sql_test.rb
... | ... | @@ -148,6 +148,13 @@ class TestSql < Minitest::Unit::TestCase |
148 | 148 | assert_order "product", ["Product A", "Product B", "Product C", "Product D"], order: "name" |
149 | 149 | end |
150 | 150 | |
151 | + def test_order_id | |
152 | + store_names ["Product A", "Product B"] | |
153 | + product_a = Product.where(name: "Product A").first | |
154 | + product_b = Product.where(name: "Product B").first | |
155 | + assert_order "product", [product_a, product_b].sort_by(&:id).map(&:name), order: {id: :asc} | |
156 | + end | |
157 | + | |
151 | 158 | def test_order_multiple |
152 | 159 | store [ |
153 | 160 | {name: "Product A", color: "blue", store_id: 1}, | ... | ... |