diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 5de6ab0..ae7b074 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -118,6 +118,24 @@ module Searchkick self end + def load(value) + spawn.load!(value) + end + + def load!(value) + options[:load] = value + self + end + + def includes(*args) + spawn.includes!(*args) + end + + def includes!(*args) + options[:includes] = Array(options[:includes]) + args + self + end + # same as Active Record def inspect entries = results.first(11).map!(&:inspect) diff --git a/test/sql_test.rb b/test/sql_test.rb index 86fa8a9..30ecaac 100644 --- a/test/sql_test.rb +++ b/test/sql_test.rb @@ -70,22 +70,26 @@ class SqlTest < Minitest::Test def test_load_false store_names ["Product A"] assert_kind_of Hash, Product.search("product", load: false).first + assert_kind_of Hash, Product.search("product", relation: true).load(false).first end def test_load_false_methods store_names ["Product A"] assert_equal "Product A", Product.search("product", load: false).first.name + assert_equal "Product A", Product.search("product", relation: true).load(false).first.name end def test_load_false_with_includes store_names ["Product A"] assert_kind_of Hash, Product.search("product", load: false, includes: [:store]).first + assert_kind_of Hash, Product.search("product", relation: true).load(false).includes(:store).first end def test_load_false_nested_object aisle = {"id" => 1, "name" => "Frozen"} store [{name: "Product A", aisle: aisle}] assert_equal aisle, Product.search("product", load: false).first.aisle.to_hash + assert_equal aisle, Product.search("product", relation: true).load(false).first.aisle.to_hash end # select -- libgit2 0.21.0