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
359 def before_validation
360   if new? && (set = self[model.sti_key])
361     exp = model.sti_key_chooser.call(self)
362     if set != exp
363       set_table = model.sti_class_from_key(set).cti_table_name
364       exp_table = model.sti_class_from_key(exp).cti_table_name
365       set_column_value("#{model.sti_key}=", exp) if set_table != exp_table
366     end
367   end
368   super
369 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
345 def delete
346   raise Sequel::Error, "can't delete frozen object" if frozen?
347   model.cti_models.reverse_each do |m|
348     cti_this(m).delete
349   end
350   self
351 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
354 def use_prepared_statements_for?(type)
355   false
356 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
379 def _insert
380   return super if model.cti_models[0] == model
381   model.cti_models.each do |m|
382     v = {}
383     m.cti_table_columns.each{|c| v[c] = @values[c] if @values.include?(c)}
384     ds = use_server(m.cti_instance_dataset)
385     if ds.supports_insert_select? && (h = ds.insert_select(v))
386       @values.merge!(h)
387     else
388       nid = ds.insert(v)
389       @values[primary_key] ||= nid
390     end
391   end
392   db.dataset.supports_insert_select? ? nil : @values[primary_key]
393 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
396 def _update(columns)
397   return super if model.cti_models[0] == model
398   model.cti_models.each do |m|
399     h = {}
400     m.cti_table_columns.each{|c| h[c] = columns[c] if columns.include?(c)}
401     unless h.empty?
402       ds = cti_this(m)
403       n = ds.update(h)
404       raise(NoExistingObject, "Attempt to update object did not result in a single row modification (SQL: #{ds.update_sql(h)})") if require_modification && n != 1
405     end
406   end
407 end
cti_this(model) click to toggle source
    # File lib/sequel/plugins/class_table_inheritance.rb
373 def cti_this(model)
374   use_server(model.cti_instance_dataset.where(model.primary_key_hash(pk)))
375 end