diff --git a/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb b/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb index b4df631f4..81b9fe61e 100644 --- a/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb +++ b/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb @@ -70,6 +70,12 @@ def __records_by_type def __records_for_klass(klass, ids) adapter = __adapter_for_klass(klass) + # Allow calling `.records()` with options: + # ex: `klass.name => [{ method: :includes, args: [:association]}, { method: :scope_name }]` + if (klass_options = @options&.dig(klass.name)) + klass_options.each { |opts| klass = klass.public_send(opts[:method], *opts[:args]) } + end + case when Elasticsearch::Model::Adapter::ActiveRecord.equal?(adapter) klass.where(klass.primary_key => ids)