module Sequel::Plugins::ClassTableInheritance::InstanceMethods
Public Instance Methods
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, line 244 def delete raise Sequel::Error, "can't delete frozen object" if frozen? m = model m.cti_tables.reverse.each do |table| m.db.from(table).filter(m.primary_key=>pk).delete end self end
Private Instance Methods
_before_validation()
click to toggle source
Set the cti_key column to the name of the model.
Calls superclass method
# File lib/sequel/plugins/class_table_inheritance.rb, line 256 def _before_validation if new? && model.cti_key && !model.cti_model_map set_column_value("#{model.cti_key}=", model.name.to_s) end super end
_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, line 265 def _insert return super if model == model.cti_base_model iid = @values[primary_key] m = model m.cti_tables.each do |table| h = {} h[m.primary_key] ||= iid if iid m.cti_columns[table].each{|c| h[c] = @values[c] if @values.include?(c)} nid = m.db.from(table).insert(h) iid ||= nid end @values[primary_key] = iid end
_update(columns)
click to toggle source
Update rows in all backing tables, using the columns in each table.
# File lib/sequel/plugins/class_table_inheritance.rb, line 280 def _update(columns) pkh = pk_hash m = model m.cti_tables.each do |table| h = {} m.cti_columns[table].each{|c| h[c] = columns[c] if columns.include?(c)} m.db.from(table).filter(pkh).update(h) unless h.empty? end end