Module | Sequel::Plugins::SingleTableInheritance::ClassMethods
In: | lib/sequel/plugins/single_table_inheritance.rb

### Methods

inherited sti_load sti_subclass_added

### Attributes

sti_dataset | [R] | The base dataset for STI, to which filters are added to get only the models for the specific STI subclass.
sti_key | [R] | The column name holding the STI key for this model
sti_key_array | [R] | Array holding keys for all subclasses of this class, used for the dataset filter in subclasses. Nil in the main class.
sti_key_map | [R] | A hash/proc with class keys and column value values, mapping the the class to a particular value given to the sti_key column. Used to set the column value when creating objects, and for the filter when retrieving objects in subclasses.
sti_model_map | [R] | A hash/proc with column value keys and class values, mapping the value of the sti_key column to the appropriate class to use.

### Public Instance methods

inherited(subclass)

Copy the necessary attributes to the subclasses, and filter the subclass‘s dataset based on the sti_kep_map entry for the class.

[Source]

         # File lib/sequel/plugins/single_table_inheritance.rb, line 102
    102:         def inherited(subclass)
    103:           super
    104:           sk = sti_key
    105:           sd = sti_dataset
    106:           skm = sti_key_map
    107:           smm = sti_model_map
    108:           key = skm[subclass]
    109:           sti_subclass_added(key)
    110:           ska = [key]
    111:           rp = dataset.row_proc
    112:           subclass.set_dataset(sd.filter(SQL::QualifiedIdentifier.new(table_name, sk)=>ska), :inherited=>true)
    113:           subclass.instance_eval do
    114:             dataset.row_proc = rp
    115:             @sti_key = sk
    116:             @sti_key_array = ska
    117:             @sti_dataset = sd
    118:             @sti_key_map = skm
    119:             @sti_model_map = smm
    120:             self.simple_table = nil
    121:           end
    122:         end

sti_load(r)

Return an instance of the class specified by sti_key, used by the row_proc.

[Source]

         # File lib/sequel/plugins/single_table_inheritance.rb, line 126
    126:         def sti_load(r)
    127:           sti_class(sti_model_map[r[sti_key]]).call(r)
    128:         end

sti_subclass_added(key)

Make sure that all subclasses of the parent class correctly include keys for all of their descendant classes.

[Source]

         # File lib/sequel/plugins/single_table_inheritance.rb, line 132
    132:         def sti_subclass_added(key)
    133:           if sti_key_array
    134:             Sequel.synchronize{sti_key_array << key}
    135:             superclass.sti_subclass_added(key)
    136:           end
    137:         end

[Validate]