module Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/update_primary_key.rb 27 def after_update 28 super 29 @pk_hash = nil 30 end
Clear the cached primary key.
Calls superclass method
Source
# File lib/sequel/plugins/update_primary_key.rb 33 def pk_hash 34 @pk_hash || super 35 end
Use the cached primary key if one is present.
Calls superclass method
Private Instance Methods
Source
# File lib/sequel/plugins/update_primary_key.rb 41 def change_column_value(column, value) 42 pk = primary_key 43 if (pk.is_a?(Array) ? pk.include?(column) : pk == column) 44 @pk_hash ||= pk_hash unless new? 45 clear_associations_using_primary_key 46 end 47 super 48 end
If the primary key column changes, clear related associations and cache the previous primary key values.
Calls superclass method
Source
# File lib/sequel/plugins/update_primary_key.rb 54 def clear_associations_using_primary_key 55 associations.keys.each do |k| 56 associations.delete(k) if model.association_reflection(k)[:type] != :many_to_one 57 end 58 end
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).
Source
# File lib/sequel/plugins/update_primary_key.rb 62 def use_prepared_statements_for?(type) 63 if type == :update 64 false 65 else 66 super if defined?(super) 67 end 68 end
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