Commit c45424eeb82d84bef779d551650eb6ecaf565993

Authored by Andrew Kane
1 parent 79e14153

Added includes method on relation

Showing 2 changed files with 13 additions and 0 deletions   Show diff stats
lib/searchkick/relation.rb
@@ -170,6 +170,18 @@ module Searchkick @@ -170,6 +170,18 @@ module Searchkick
170 end 170 end
171 171
172 # experimental 172 # experimental
  173 + def includes(*values)
  174 + clone.includes!(*values)
  175 + end
  176 +
  177 + # experimental
  178 + def includes!(*values)
  179 + check_loaded
  180 + (@options[:includes] ||= []).concat(values)
  181 + self
  182 + end
  183 +
  184 + # experimental
173 def only(*keys) 185 def only(*keys)
174 Relation.new(@model, @term, **@options.slice(*keys)) 186 Relation.new(@model, @term, **@options.slice(*keys))
175 end 187 end
test/query_test.rb
@@ -61,6 +61,7 @@ class QueryTest < Minitest::Test @@ -61,6 +61,7 @@ class QueryTest < Minitest::Test
61 61
62 store_names ["Product A"] 62 store_names ["Product A"]
63 assert Product.search("product", includes: [:store]).first.association(:store).loaded? 63 assert Product.search("product", includes: [:store]).first.association(:store).loaded?
  64 + assert Product.search("product").includes(:store).first.association(:store).loaded?
64 end 65 end
65 66
66 def test_model_includes 67 def test_model_includes