20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/sequel/plugins/jsonapi_eager.rb', line 20
def jsonapi_eager(includes)
includes = includes.split(",") if includes.is_a?(String)
includes.each do |relationship|
association_name, association_include = relationship.split(".", 2)
association_dataset = send("#{association_name}_dataset")
.jsonapi_eager(association_include.to_s)
association_reflection = self.class.association_reflections.fetch(association_name.to_sym)
if association_reflection[:type].to_s =~ /one$/
associations[association_name.to_sym] = association_dataset.all[0]
else
associations[association_name.to_sym] = association_dataset.all
end
end
self
end
|