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 
     | 
    
      # File 'backend/app/model/mixins/components_add_children.rb', line 11
def add_children(children)
  children.children.each do |child|
    obj = JSONModel(self.class.node_record_type.intern).from_hash(child)
    root_model = Kernel.const_get(self.class.root_record_type.camelize)
    node_model = Kernel.const_get(self.class.node_record_type.camelize)
    if root_model == self.class
      obj[self.class.root_record_type] = {
        'ref' => self.uri
      }
    else
      obj[self.class.root_record_type] = {
        'ref' => self.class.uri_for(self.class.root_record_type, self[:root_record_id])
      }
      obj['parent'] = {
        'ref' => self.uri
      }
    end
    node_model.create_from_json(obj)
  end
end
     |