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.
128: def inherited(subclass)
129: cc = cti_columns
130: ck = cti_key
131: ct = cti_tables.dup
132: ctm = cti_table_map.dup
133: cbm = cti_base_model
134: pk = primary_key
135: ds = dataset
136: subclass.instance_eval do
137: raise(Error, "cannot create anonymous subclass for model class using class_table_inheritance") if !(n = name) || n.empty?
138: table = ctm[n.to_sym] || implicit_table_name
139: columns = db.from(table).columns
140: @cti_key = ck
141: @cti_tables = ct + [table]
142: @cti_columns = cc.merge(table=>columns)
143: @cti_table_map = ctm
144: @cti_base_model = cbm
145:
146:
147:
148: set_dataset(ds.join(table, [pk]))
149: set_columns(self.columns)
150: end
151: super
152: subclass.instance_eval do
153: m = method(:constantize)
154: dataset.row_proc = if cti_key
155: lambda{|r| (m.call(r[ck]) rescue subclass).call(r)}
156: else
157: subclass
158: end
159: (columns - [cbm.primary_key]).each{|a| define_lazy_attribute_getter(a)}
160: cti_tables.reverse.each do |table|
161: db.schema(table).each{|k,v| db_schema[k] = v}
162: end
163: end
164: end