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

added includes method to enable explicit join with associated tables #1927

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/rails_admin/adapters/active_record.rb
Expand Up @@ -110,9 +110,13 @@ def add(field, value, operator)
end

def build
scope = @scope.where(@statements.join(' OR '), *@values)
scope = scope.references(*(@tables.uniq)) if @tables.any?
scope
join_tables = @tables.uniq
join_tables.delete(@scope.name.tableize) # exclude the scope table itself
if join_tables.any?
@scope.includes(*join_tables).where(@statements.join(' OR '), *@values).references(*join_tables)
else
@scope.where(@statements.join(' OR '), *@values)
end
end
end

Expand Down