32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/hq/graphql/ext/object_extensions.rb', line 32
def with_model(model_name, attributes: true, associations: true, auto_nil: true, enums: true)
self.model_name = model_name
self.auto_load_attributes = attributes
self.auto_load_associations = associations
self.auto_load_enums = enums
lazy_load do
model_columns.each do |column|
field_from_column(column, auto_nil: auto_nil)
end
model_associations.each do |association|
next if resource_reflections[association.name.to_s]
field_from_association(association, auto_nil: auto_nil)
end
resource_reflections.values.each do |resource_reflection|
reflection = resource_reflection.reflection(model_klass)
next unless reflection
field_from_association(reflection, auto_nil: auto_nil, internal_association: true, &resource_reflection.block)
end
end
end
|