module Sequel::Plugins::ClassTableInheritance::InstanceMethods

Public 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
392 def before_validation
393   if new? && (set = self[model.sti_key])
394     exp = model.sti_key_chooser.call(self)
395     if set != exp
396       set_table = model.sti_class_from_key(set).cti_table_name
397       exp_table = model.sti_class_from_key(exp).cti_table_name
398       set_column_value("#{model.sti_key}=", exp) if set_table != exp_table
399     end
400   end
401   super
402 end
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
378 def delete
379   raise Sequel::Error, "can't delete frozen object" if frozen?
380   model.cti_models.reverse_each do |m|
381     cti_this(m).delete
382   end
383   self
384 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
387 def use_prepared_statements_for?(type)
388   false
389 end

Private Instance Methods

_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
412 def _insert
413   return super if model.cti_models[0] == model
414   model.cti_models.each do |m|
415     v = {}
416     m.cti_table_columns.each{|c| v[c] = @values[c] if @values.include?(c)}
417     ds = use_server(m.cti_instance_dataset)
418     if ds.supports_insert_select? && (h = ds.insert_select(v))
419       @values.merge!(h)
420     else
421       nid = ds.insert(v)
422       @values[primary_key] ||= nid
423     end
424   end
425   db.dataset.supports_insert_select? ? nil : @values[primary_key]
426 end
_update(columns) click to toggle source

Update rows in all backing tables, using the columns in each table.

Calls superclass method
    # File lib/sequel/plugins/class_table_inheritance.rb
429 def _update(columns)
430   return super if model.cti_models[0] == model
431   model.cti_models.each do |m|
432     h = {}
433     m.cti_table_columns.each{|c| h[c] = columns[c] if columns.include?(c)}
434     unless h.empty?
435       ds = cti_this(m)
436       n = ds.update(h)
437       raise(NoExistingObject, "Attempt to update object did not result in a single row modification (SQL: #{ds.update_sql(h)})") if require_modification && n != 1
438     end
439   end
440 end
cti_this(model) click to toggle source
    # File lib/sequel/plugins/class_table_inheritance.rb
406 def cti_this(model)
407   use_server(model.cti_instance_dataset.where(model.primary_key_hash(pk)))
408 end