module Sequel::Plugins::AssociationPks::InstanceMethods

Private Instance Methods

convert_cpk_array(opts, cpks) click to toggle source

If any of associated class's composite primary key column types is integer, typecast the appropriate values to integer before using them.

# File lib/sequel/plugins/association_pks.rb, line 143
def convert_cpk_array(opts, cpks)
  if klass = opts.associated_class and sch = klass.db_schema and (cols = sch.values_at(*klass.primary_key)).all? and (convs = cols.map{|c| c[:type] == :integer}).any?
    cpks.map do |cpk|
      cpk.zip(convs).map do |pk, conv|
        conv ? model.db.typecast_value(:integer, pk) : pk
      end
    end
  else
    cpks
  end
end
convert_pk_array(opts, pks) click to toggle source

If the associated class's primary key column type is integer, typecast all provided values to integer before using them.

# File lib/sequel/plugins/association_pks.rb, line 157
def convert_pk_array(opts, pks)
  if klass = opts.associated_class and sch = klass.db_schema and col = sch[klass.primary_key] and col[:type] == :integer
    pks.map{|pk| model.db.typecast_value(:integer, pk)}
  else
    pks
  end
end