Skip to content

Commit

Permalink
Use left joins instead of inner join when searching
Browse files Browse the repository at this point in the history
  • Loading branch information
samnang committed Sep 3, 2020
1 parent 1234bc7 commit 8289b1c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/administrate/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/administrate/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8289b1c

Please sign in to comment.