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
|
# File 'lib/multiple_table_inheritance/child/base.rb', line 14
def inherits_from(association_name, options={})
options = Base::default_options.merge(options.to_options)
inherit_methods = options.delete(:methods)
extend FinderMethods, SharedMethods
include InstanceMethods, SharedMethods
include DelegateMethods if inherit_methods
self.parent_association_name = association_name.to_sym
self.primary_key = "#{parent_association_name}_id"
define_method("#{parent_association_name}_with_autobuild") do
send("#{parent_association_name}_without_autobuild") || send("build_#{parent_association_name}")
end
inherited_columns_and_associations.each do |name|
delegate name, "#{name}=", :to => parent_association_name
end
parent_association_class.accessible_attributes.each do |attr|
attr_accessible attr.to_sym
end
belongs_to parent_association_name, options
alias_method_chain parent_association_name, :autobuild
before_validation :set_association_subtype
validate :parent_association_must_be_valid
before_save :parent_association_must_be_saved
end
|