module Switchman::ActiveRecord::StatementCache::BindMap

Public Instance Methods

bind(values, current_shard, target_shard) click to toggle source

performs id transposition here instead of query_methods.rb

# File lib/switchman/active_record/statement_cache.rb, line 53
def bind(values, current_shard, target_shard)
  bas = @bound_attributes.dup
  @indexes.each_with_index do |offset, i|
    ba = bas[offset]
    new_value = if ba.is_a?(::ActiveRecord::Relation::QueryAttribute) && ba.value.sharded
                  Shard.relative_id_for(values[i], current_shard, target_shard || current_shard)
                else
                  values[i]
                end
    bas[offset] = ba.with_cast_value(new_value)
  end
  bas
end
primary_value_index() click to toggle source
# File lib/switchman/active_record/statement_cache.rb, line 67
def primary_value_index
  primary_ba_index = @bound_attributes.index do |ba|
    ba.is_a?(::ActiveRecord::Relation::QueryAttribute) && ba.value.primary
  end
  @indexes.index(primary_ba_index) if primary_ba_index
end