From 8289b1cc3333f6dfb6a07dc4984f865f6fe04609 Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Mon, 23 Mar 2020 18:07:50 +0700 Subject: [PATCH] Use left joins instead of inner join when searching --- lib/administrate/search.rb | 2 +- spec/lib/administrate/search_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/administrate/search.rb b/lib/administrate/search.rb index fe0f292b56..07cc9acf2e 100644 --- a/lib/administrate/search.rb +++ b/lib/administrate/search.rb @@ -109,7 +109,7 @@ def search_attributes def search_results(resources) resources. - joins(tables_to_join). + left_joins(tables_to_join). where(query_template, *query_values) end diff --git a/spec/lib/administrate/search_spec.rb b/spec/lib/administrate/search_spec.rb index 411078639d..f91a5f51d6 100644 --- a/spec/lib/administrate/search_spec.rb +++ b/spec/lib/administrate/search_spec.rb @@ -152,14 +152,14 @@ class User < ApplicationRecord; end it "joins with the correct association table to query" do allow(scoped_object).to receive(:where) - expect(scoped_object).to receive(:joins).with(%i(role author address)). + expect(scoped_object).to receive(:left_joins).with(%i(role author address)). and_return(scoped_object) search.run end it "builds the 'where' clause using the joined tables" do - allow(scoped_object).to receive(:joins).with(%i(role author address)). + allow(scoped_object).to receive(:left_joins).with(%i(role author address)). and_return(scoped_object) expect(scoped_object).to receive(:where).with(*expected_query)