Module: ObjectGraph::ClassMethods

Defined in:
backend/app/model/ASModel_object_graph.rb

Instance Method Summary collapse

Instance Method Details

#calculate_object_graph(object_graph, opts = {}) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'backend/app/model/ASModel_object_graph.rb', line 135

def calculate_object_graph(object_graph, opts = {})
  object_graph.models.each do |model|
    next unless model.respond_to?(:nested_records)
    model.nested_records.each do |nr|
      association = nr[:association]

      if association[:type] != :many_to_many
        nested_model = Kernel.const_get(association[:class_name])

        ids = nested_model.filter(association[:key] => object_graph.ids_for(model)).
                           select(:id).map {|row|
          row[:id]
        }

        object_graph.add_objects(nested_model, ids)
      end
    end
  end

  object_graph
end