89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/active_record/defaults.rb', line 89
def apply_default_attribute_values(attributes)
attribute_keys = (attributes || {}).keys.map!(&:to_s)
if attribute_defaults = self.class.read_inheritable_attribute(:attribute_defaults)
attribute_defaults.each do |default|
next if attribute_keys.include?(default.attribute)
reflection = self.class.reflections[default.attribute.to_sym]
if reflection and reflection.macro == :belongs_to and attribute_keys.include?(reflection.primary_key_name)
next
end
reflection = self.class.reflections.values.find { |r| r.respond_to?(:primary_key_name) && r.primary_key_name == default.attribute }
if reflection and reflection.macro == :belongs_to and attribute_keys.include?(reflection.name.to_s)
next
end
send("#{default.attribute}=", default.value(self))
end
end
end
|