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
27 def after_update
28   super
29   @pk_hash = nil
30 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
33 def pk_hash
34   @pk_hash || super
35 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
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
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
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
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
62 def use_prepared_statements_for?(type)
63   if type == :update
64     false
65   else
66     super if defined?(super)
67   end
68 end