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 382 def before_validation 383 if new? && (set = self[model.sti_key]) 384 exp = model.sti_key_chooser.call(self) 385 if set != exp 386 set_table = model.sti_class_from_key(set).cti_table_name 387 exp_table = model.sti_class_from_key(exp).cti_table_name 388 set_column_value("#{model.sti_key}=", exp) if set_table != exp_table 389 end 390 end 391 super 392 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 368 def delete 369 raise Sequel::Error, "can't delete frozen object" if frozen? 370 model.cti_models.reverse_each do |m| 371 cti_this(m).delete 372 end 373 self 374 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 377 def use_prepared_statements_for?(type) 378 false 379 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 402 def _insert 403 return super if model.cti_models[0] == model 404 model.cti_models.each do |m| 405 v = {} 406 m.cti_table_columns.each{|c| v[c] = @values[c] if @values.include?(c)} 407 ds = use_server(m.cti_instance_dataset) 408 if ds.supports_insert_select? && (h = ds.insert_select(v)) 409 @values.merge!(h) 410 else 411 nid = ds.insert(v) 412 @values[primary_key] ||= nid 413 end 414 end 415 db.dataset.supports_insert_select? ? nil : @values[primary_key] 416 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 419 def _update(columns) 420 return super if model.cti_models[0] == model 421 model.cti_models.each do |m| 422 h = {} 423 m.cti_table_columns.each{|c| h[c] = columns[c] if columns.include?(c)} 424 unless h.empty? 425 ds = cti_this(m) 426 n = ds.update(h) 427 raise(NoExistingObject, "Attempt to update object did not result in a single row modification (SQL: #{ds.update_sql(h)})") if require_modification && n != 1 428 end 429 end 430 end
cti_this(model)
click to toggle source
# File lib/sequel/plugins/class_table_inheritance.rb 396 def cti_this(model) 397 use_server(model.cti_instance_dataset.where(model.primary_key_hash(pk))) 398 end