8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/active_loaders/datasource_adapter.rb', line 8
def initialize_with_loaders(objects, options = {})
datasource_class = options.delete(:datasource)
adapter = Datasource.orm_adapters.find { |a| a.is_scope?(objects) }
if adapter && !adapter.scope_loaded?(objects)
scope = begin
objects
.for_serializer(options[:serializer])
.datasource_params(*[options[:loader_params]].compact)
rescue NameError
if options[:serializer].nil?
return initialize_without_loaders(objects, options)
else
raise
end
end
if datasource_class
scope = scope.with_datasource(datasource_class)
end
records = adapter.scope_to_records(scope)
if objects.respond_to?(:proxy_association)
objects.proxy_association.target = records
end
initialize_without_loaders(records, options)
else
initialize_without_loaders(objects, options)
end
end
|