module Sequel::Plugins::ClassTableInheritance::ClassMethods

def inherited(subclass)

be mappable to a table.
allow anonymous subclasses to be created, since they would not
Add the appropriate data structures to the subclass. Does not
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
    # Need to set dataset and columns before calling super so that
    # the main column accessor module is included in the class before any
    # plugin accessor modules (such as the lazy attributes accessor module).
    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

def primary_key

foreign key with the same name referencing it in each model subclass.
The primary key in the parent/base/root model, which should have a
def primary_key
  return super if self == cti_base_model
  cti_base_model.primary_key
end

def table_name

by any superclasses).
The table name for the current model class's main table (not used
def table_name
  self == cti_base_model ? super : cti_tables.last
end