Set the cti_key column to the name of the model.
# File lib/sequel/plugins/class_table_inheritance.rb, line 182 def before_create send("#{model.cti_key}=", model.name.to_s) if model.cti_key super end
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 189 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
Insert rows into all backing tables, using the columns in each table.
# File lib/sequel/plugins/class_table_inheritance.rb, line 202 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 rows in all backing tables, using the columns in each table.
# File lib/sequel/plugins/class_table_inheritance.rb, line 217 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