Skip to content

Allow chaining scope or includes when searching across multiple models #991

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

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Allow chaining scope or includes when searching across multiple models
Must use `klass.name` instead of klass (#912)
  • Loading branch information
SeanLF authored Apr 9, 2021
commit 10640cac10dfc0db3f546197f1b1d7f398323fdf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def __records_by_type
def __records_for_klass(klass, ids)
adapter = __adapter_for_klass(klass)

# Allow calling `.records()` with options:
# klass.name => [{ method: :includes, args: [:association]}, { method: :scope_name }]
if (klass_options = @options.dig(klass.name))
klass_options.each { klass = klass.public_send(_1[:method], *_1[:args]) }
end

case
when Elasticsearch::Model::Adapter::ActiveRecord.equal?(adapter)
klass.where(klass.primary_key => ids)
Expand Down