Commit 43db098d2bc17dc80ed274b1b908aa39bcce1b63

Authored by Andrew Kane
1 parent c11635c1
Exists in master

Added model method to Searchkick::Relation and don't load relation when klass method is called

1 ## 5.0.5 (unreleased) 1 ## 5.0.5 (unreleased)
2 2
  3 +- Added `model` method to `Searchkick::Relation`
3 - Fixed deprecation warning with `redis` gem 4 - Fixed deprecation warning with `redis` gem
4 5
5 ## 5.0.4 (2022-06-16) 6 ## 5.0.4 (2022-06-16)
lib/searchkick/relation.rb
@@ -8,6 +8,9 @@ module Searchkick @@ -8,6 +8,9 @@ module Searchkick
8 delegate :body, :params, to: :query 8 delegate :body, :params, to: :query
9 delegate_missing_to :private_execute 9 delegate_missing_to :private_execute
10 10
  11 + attr_reader :model
  12 + alias_method :klass, :model
  13 +
11 def initialize(model, term = "*", **options) 14 def initialize(model, term = "*", **options)
12 @model = model 15 @model = model
13 @term = term 16 @term = term
test/relation_test.rb
@@ -34,6 +34,16 @@ class RelationTest < Minitest::Test @@ -34,6 +34,16 @@ class RelationTest < Minitest::Test
34 assert_equal ["Product A", "Product B"], Product.search("product").pluck(:name).sort 34 assert_equal ["Product A", "Product B"], Product.search("product").pluck(:name).sort
35 end 35 end
36 36
  37 + def test_model
  38 + assert_equal Product, Product.search("product").model
  39 + assert_nil Searchkick.search("product").model
  40 + end
  41 +
  42 + def test_klass
  43 + assert_equal Product, Product.search("product").klass
  44 + assert_nil Searchkick.search("product").klass
  45 + end
  46 +
37 # TODO uncomment in 6.0 47 # TODO uncomment in 6.0
38 # def test_to_yaml 48 # def test_to_yaml
39 # store_names ["Product A", "Product B"] 49 # store_names ["Product A", "Product B"]