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.



351
352
353
354
355
356
357
358
359
360
361
# File 'lib/sequel/plugins/class_table_inheritance.rb', line 351

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:



337
338
339
340
341
342
343
# File 'lib/sequel/plugins/class_table_inheritance.rb', line 337

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) ⇒ Boolean

Don't allow use of prepared statements.



346
347
348
# File 'lib/sequel/plugins/class_table_inheritance.rb', line 346

def use_prepared_statements_for?(type)
  false
end