Commit 76b7c289c690464fee07320f21ae14efc813aefb

Authored by Andrew Kane
1 parent f3e66d41

No way around select option always returning arrays - #225

Showing 2 changed files with 8 additions and 2 deletions   Show diff stats
lib/searchkick/results.rb
... ... @@ -44,7 +44,7 @@ module Searchkick
44 44 if hit["_source"]
45 45 hit.except("_source").merge(hit["_source"])
46 46 else
47   - hit.except("fields").merge(Hash[ hit["fields"].map{|k, v| [k, v.first] } ])
  47 + hit.except("fields").merge(hit["fields"])
48 48 end
49 49 result["id"] ||= result["_id"] # needed for legacy reasons
50 50 Hashie::Mash.new(result)
... ...
test/sql_test.rb
... ... @@ -283,7 +283,13 @@ class TestSql < Minitest::Unit::TestCase
283 283 store [{name: "Product A", store_id: 1}]
284 284 result = Product.search("product", load: false, select: [:name, :store_id]).first
285 285 assert_equal %w[id name store_id], result.keys.reject{|k| k.start_with?("_") }.sort
286   - assert_equal "Product A", result.name
  286 + assert_equal ["Product A"], result.name # this is not great
  287 + end
  288 +
  289 + def test_select_array
  290 + store [{name: "Product A", user_ids: [1, 2]}]
  291 + result = Product.search("product", load: false, select: [:user_ids]).first
  292 + assert_equal [1, 2], result.user_ids
287 293 end
288 294  
289 295 # TODO see if Mongoid is loaded
... ...