4
5
6
7
8
9
10
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/citier/child_instance_methods.rb', line 4
def save(options={})
return false if (options[:validate] != false && !self.valid?)
citier_debug("SAVING #{self.class.to_s}")
self.run_callbacks(:save) do
self.run_callbacks(self.new_record? ? :create : :update) do
attributes_for_parent = self.attributes.reject { |key,value| !self.class.superclass.column_names.include?(key) }
changed_attributes_for_parent = self.changed_attributes.reject { |key,value| !self.class.superclass.column_names.include?(key) }
attributes_for_current = self.attributes.reject { |key,value| self.class.superclass.column_names.include?(key) }
changed_attributes_for_current = self.changed_attributes.reject { |key,value| self.class.superclass.column_names.include?(key) }
citier_debug("Attributes for #{self.class.superclass.to_s}: #{attributes_for_parent.inspect}")
citier_debug("Changed attributes for #{self.class.superclass.to_s}: #{changed_attributes_for_parent.keys.inspect}")
citier_debug("Attributes for #{self.class.to_s}: #{attributes_for_current.inspect}")
citier_debug("Changed attributes for #{self.class.to_s}: #{changed_attributes_for_current.keys.inspect}")
parent = self.class.superclass.new
parent.force_attributes(attributes_for_parent, :merge => true)
changed_attributes_for_parent["id"] = 0 parent.force_changed_attributes(changed_attributes_for_parent)
parent.id = self.id if id
parent.type = self.type
parent.is_new_record(new_record?)
parent_saved = parent.save
self.id = parent.id
if !parent_saved
citier_debug("Class (#{self.class.superclass.to_s}) could not be saved")
citier_debug("Errors = #{parent.errors.to_s}")
return false end
if !attributes_for_current.empty?
current = self.class::Writable.new
current.force_attributes(attributes_for_current, :merge => true)
current.force_changed_attributes(changed_attributes_for_current)
current.id = self.id
current.is_new_record(new_record?)
current_saved = current.save
current.after_save_change_request if current.respond_to?('after_save_change_request')
if !current_saved
citier_debug("Class (#{self.class.superclass.to_s}) could not be saved")
citier_debug("Errors = #{current.errors.to_s}")
return false end
end
is_new_record(false)
self.force_changed_attributes({})
end
end
return true
end
|