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
41
42
43
44
45
46
47
|
# 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
begin
node_model.create_from_json(obj)
rescue Sequel::ValidationFailed => e
e.errors.keys.each do |key|
next unless obj[key]
e.errors[key].map! { |msg| msg << " ( #{key}: #{obj[key]} )"}
end
raise e
end
end
end
|