Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use left joins instead of inner join when searching #1581

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 4 additions & 2 deletions spec/lib/administrate/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,16 @@ 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