module Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
Public Instance Methods
after_update()
click to toggle source
Clear the cached primary key.
Calls superclass method
# File lib/sequel/plugins/update_primary_key.rb, line 25 def after_update super @pk_hash = nil end
pk_hash()
click to toggle source
Use the cached primary key if one is present.
Calls superclass method
# File lib/sequel/plugins/update_primary_key.rb, line 31 def pk_hash @pk_hash || super end
Private Instance Methods
change_column_value(column, value)
click to toggle source
If the primary key column changes, clear related associations and cache the previous primary key values.
Calls superclass method
# File lib/sequel/plugins/update_primary_key.rb, line 39 def change_column_value(column, value) pk = primary_key if (pk.is_a?(Array) ? pk.include?(column) : pk == column) @pk_hash ||= pk_hash unless new? clear_associations_using_primary_key end super end
clear_associations_using_primary_key()
click to toggle source
Clear associations that are likely to be tied to the primary key. Note that this currently can clear additional options that don't reference the primary key (such as one_to_many columns referencing a column other than the primary key).
# File lib/sequel/plugins/update_primary_key.rb, line 52 def clear_associations_using_primary_key associations.keys.each do |k| associations.delete(k) if model.association_reflection(k)[:type] != :many_to_one end end
use_prepared_statements_for?(type)
click to toggle source
Do not use prepared statements for update queries, since they don't work in the case where the primary key has changed.
Calls superclass method
# File lib/sequel/plugins/update_primary_key.rb, line 60 def use_prepared_statements_for?(type) if type == :update false else super end end