Module: Sequel::Plugins::SingleTableInheritance::ClassMethods

Defined in:
lib/sequel/lib/sequel/plugins/single_table_inheritance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sti_datasetObject (readonly)

The base dataset for STI, to which filters are added to get only the models for the specific STI subclass.


33
34
35
# File 'lib/sequel/lib/sequel/plugins/single_table_inheritance.rb', line 33

def sti_dataset
  @sti_dataset
end

#sti_keyObject (readonly)

The column name holding the STI key for this model


36
37
38
# File 'lib/sequel/lib/sequel/plugins/single_table_inheritance.rb', line 36

def sti_key
  @sti_key
end

Instance Method Details

#inherited(subclass) ⇒ Object

Copy the sti_key and sti_dataset to the subclasses, and filter the subclass's dataset so it is restricted to rows where the key column matches the subclass's name.


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sequel/lib/sequel/plugins/single_table_inheritance.rb', line 41

def inherited(subclass)
  super
  sk = sti_key
  sd = sti_dataset
  subclass.set_dataset(sd.filter(sk=>subclass.name.to_s), :inherited=>true)
  subclass.instance_eval do
    @sti_key = sk
    @sti_dataset = sd
    @simple_table = nil
  end
end