Add the appropriate data structures to the subclass. Does not allow
anonymous subclasses to be created, since they would not be mappable to a
table.
def inherited(subclass)
cc = cti_columns
ck = cti_key
ct = cti_tables.dup
ctm = cti_table_map.dup
cbm = cti_base_model
pk = primary_key
ds = dataset
subclass.instance_eval do
raise(Error, "cannot create anonymous subclass for model class using class_table_inheritance") if !(n = name) || n.empty?
table = ctm[n.to_sym] || implicit_table_name
columns = db.from(table).columns
@cti_key = ck
@cti_tables = ct + [table]
@cti_columns = cc.merge(table=>columns)
@cti_table_map = ctm
@cti_base_model = cbm
set_dataset(ds.join(table, [pk]))
set_columns(self.columns)
end
super
subclass.instance_eval do
m = method(:constantize)
dataset.row_proc = if cti_key
lambda{|r| (m.call(r[ck]) rescue subclass).call(r)}
else
subclass
end
(columns - [cbm.primary_key]).each{|a| define_lazy_attribute_getter(a)}
cti_tables.reverse.each do |table|
db.schema(table).each{|k,v| db_schema[k] = v}
end
end
end