module Sequel::Plugins::ClassTableInheritance::InstanceMethods
Public Instance Methods
delete()
click to toggle source
Delete the row from all backing tables, starting from the most recent table and going through all superclasses.
# File lib/sequel/plugins/class_table_inheritance.rb, line 325 def delete raise Sequel::Error, "can't delete frozen object" if frozen? model.cti_models.reverse_each do |m| cti_this(m).delete end self end
use_prepared_statements_for?(type)
click to toggle source
Don't allow use of prepared statements.
# File lib/sequel/plugins/class_table_inheritance.rb, line 334 def use_prepared_statements_for?(type) false end
Private Instance Methods
_before_validation()
click to toggle source
Set the sti_key column based on the sti_key_map.
Calls superclass method
# File lib/sequel/plugins/class_table_inheritance.rb, line 345 def _before_validation if new? && (set = self[model.sti_key]) exp = model.sti_key_chooser.call(self) if set != exp set_table = model.sti_class_from_key(set).table_name exp_table = model.sti_class_from_key(exp).table_name set_column_value("#{model.sti_key}=", exp) if set_table != exp_table end end super end
_insert()
click to toggle source
Insert rows into all backing tables, using the columns in each table.
Calls superclass method
# File lib/sequel/plugins/class_table_inheritance.rb, line 359 def _insert return super if model.cti_tables.length == 1 model.cti_models.each do |m| v = {} m.cti_table_columns.each{|c| v[c] = @values[c] if @values.include?(c)} ds = use_server(m.cti_instance_dataset) if ds.supports_insert_select? && (h = ds.insert_select(v)) @values.merge!(h) else nid = ds.insert(v) @values[primary_key] ||= nid end end db.dataset.supports_insert_select? ? nil : @values[primary_key] end
_update(columns)
click to toggle source
Update rows in all backing tables, using the columns in each table.
# File lib/sequel/plugins/class_table_inheritance.rb, line 376 def _update(columns) model.cti_models.each do |m| h = {} m.cti_table_columns.each{|c| h[c] = columns[c] if columns.include?(c)} cti_this(m).update(h) unless h.empty? end end
cti_this(model)
click to toggle source
# File lib/sequel/plugins/class_table_inheritance.rb, line 340 def cti_this(model) use_server(model.cti_instance_dataset.where(model.primary_key_hash(pk))) end