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
31 def after_update
32   super
33   @pk_hash = nil
34 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
37 def pk_hash
38   @pk_hash || super
39 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
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
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
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
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
66 def use_prepared_statements_for?(type)
67   if type == :update
68     false
69   else
70     super if defined?(super)
71   end
72 end