module Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/update_primary_key.rb 31 def after_update 32 super 33 @pk_hash = nil 34 end
Clear the cached primary key.
Calls superclass method
Source
# File lib/sequel/plugins/update_primary_key.rb 37 def pk_hash 38 @pk_hash || super 39 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 45 def change_column_value(column, value) 46 pk = primary_key 47 if (pk.is_a?(Array) ? pk.include?(column) : pk == column) 48 @pk_hash ||= pk_hash unless new? 49 clear_associations_using_primary_key 50 end 51 super 52 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 58 def clear_associations_using_primary_key 59 associations.keys.each do |k| 60 associations.delete(k) if model.association_reflection(k)[:type] != :many_to_one 61 end 62 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 66 def use_prepared_statements_for?(type) 67 if type == :update 68 false 69 else 70 super if defined?(super) 71 end 72 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