module Sequel::Plugins::ClassTableInheritance::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/class_table_inheritance.rb 387 def before_validation 388 if new? && (set = self[model.sti_key]) 389 exp = model.sti_key_chooser.call(self) 390 if set != exp 391 set_table = model.sti_class_from_key(set).cti_table_name 392 exp_table = model.sti_class_from_key(exp).cti_table_name 393 set_column_value("#{model.sti_key}=", exp) if set_table != exp_table 394 end 395 end 396 super 397 end
Set the sti_key column based on the sti_key_map.
Calls superclass method
Source
# 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
Delete the row from all backing tables, starting from the most recent table and going through all superclasses.
Private Instance Methods
Source
# File lib/sequel/plugins/class_table_inheritance.rb 407 def _insert 408 return super if model.cti_models[0] == model 409 model.cti_models.each do |m| 410 v = {} 411 m.cti_table_columns.each{|c| v[c] = @values[c] if @values.include?(c)} 412 ds = use_server(m.cti_instance_dataset) 413 if ds.supports_insert_select? && (h = ds.insert_select(v)) 414 @values.merge!(h) 415 else 416 nid = ds.insert(v) 417 @values[primary_key] ||= nid 418 end 419 end 420 @values[primary_key] 421 end
Insert rows into all backing tables, using the columns in each table.
Calls superclass method
Source
# File lib/sequel/plugins/class_table_inheritance.rb 424 def _update(columns) 425 return super if model.cti_models[0] == model 426 model.cti_models.each do |m| 427 h = {} 428 m.cti_table_columns.each{|c| h[c] = columns[c] if columns.include?(c)} 429 unless h.empty? 430 ds = cti_this(m) 431 n = ds.update(h) 432 raise(NoExistingObject, "Attempt to update object did not result in a single row modification (SQL: #{ds.update_sql(h)})") if require_modification && n != 1 433 end 434 end 435 end
Update rows in all backing tables, using the columns in each table.
Calls superclass method
Source
# File lib/sequel/plugins/class_table_inheritance.rb 401 def cti_this(model) 402 use_server(model.cti_instance_dataset.where(model.primary_key_hash(pk))) 403 end