Clear the cached primary key.
# File lib/sequel/plugins/update_primary_key.rb, line 25 def after_update super @pk_hash = nil end
Use the cached primary key if one is present.
# File lib/sequel/plugins/update_primary_key.rb, line 31 def pk_hash @pk_hash || super end
If the primary key column changes, clear related associations and cache the previous primary key values.
# 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 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