Module: Sequel::Plugins::SingleTableInheritance::ClassMethods
- Defined in:
- lib/sequel/plugins/single_table_inheritance.rb
Instance Attribute Summary collapse
-
#sti_dataset ⇒ Object
readonly
The base dataset for STI, to which filters are added to get only the models for the specific STI subclass.
-
#sti_key ⇒ Object
readonly
The column name holding the STI key for this model.
Instance Method Summary collapse
-
#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.
-
#sti_load(r) ⇒ Object
Return an instance of the class specified by sti_key, used by the row_proc.
Instance Attribute Details
#sti_dataset ⇒ Object (readonly)
The base dataset for STI, to which filters are added to get only the models for the specific STI subclass.
32 33 34 |
# File 'lib/sequel/plugins/single_table_inheritance.rb', line 32 def sti_dataset @sti_dataset end |
#sti_key ⇒ Object (readonly)
The column name holding the STI key for this model
35 36 37 |
# File 'lib/sequel/plugins/single_table_inheritance.rb', line 35 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.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sequel/plugins/single_table_inheritance.rb', line 40 def inherited(subclass) super sk = sti_key sd = sti_dataset subclass.set_dataset(sd.filter(SQL::QualifiedIdentifier.new(table_name, sk)=>subclass.name.to_s), :inherited=>true) subclass.instance_eval do @sti_key = sk @sti_dataset = sd @simple_table = nil end end |
#sti_load(r) ⇒ Object
Return an instance of the class specified by sti_key, used by the row_proc.
54 55 56 57 58 59 60 61 62 |
# File 'lib/sequel/plugins/single_table_inheritance.rb', line 54 def sti_load(r) v = r[sti_key] model = if (v && v != '') constantize(v) rescue self else self end model.load(r) end |