Skip to content

Commit 10640ca

Browse files
authored
Allow chaining scope or includes when searching across multiple models
Must use `klass.name` instead of klass (#912)
1 parent a4ec07b commit 10640ca

File tree

1 file changed

+6
-0
lines changed
  • elasticsearch-model/lib/elasticsearch/model/adapters

1 file changed

+6
-0
lines changed

elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def __records_by_type
7070
def __records_for_klass(klass, ids)
7171
adapter = __adapter_for_klass(klass)
7272

73+
# Allow calling `.records()` with options:
74+
# klass.name => [{ method: :includes, args: [:association]}, { method: :scope_name }]
75+
if (klass_options = @options.dig(klass.name))
76+
klass_options.each { klass = klass.public_send(_1[:method], *_1[:args]) }
77+
end
78+
7379
case
7480
when Elasticsearch::Model::Adapter::ActiveRecord.equal?(adapter)
7581
klass.where(klass.primary_key => ids)

0 commit comments

Comments
 (0)