Module: Sequel::Plugins::ClassTableInheritance::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#before_validationObject

Set the sti_key column based on the sti_key_map.



387
388
389
390
391
392
393
394
395
396
397
# File 'lib/sequel/plugins/class_table_inheritance.rb', line 387

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).cti_table_name
      exp_table = model.sti_class_from_key(exp).cti_table_name
      set_column_value("#{model.sti_key}=", exp) if set_table != exp_table
    end
  end
  super
end

#deleteObject

Delete the row from all backing tables, starting from the most recent table and going through all superclasses.

Raises:



378
379
380
381
382
383
384
# File 'lib/sequel/plugins/class_table_inheritance.rb', line 378

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