Module: Switchman::ActiveRecord::StatementCache::BindMap
- Defined in:
- lib/switchman/active_record/statement_cache.rb
Instance Method Summary collapse
-
#bind(values, current_shard, target_shard) ⇒ Object
performs id transposition here instead of query_methods.rb.
- #primary_value_index ⇒ Object
Instance Method Details
#bind(values, current_shard, target_shard) ⇒ Object
performs id transposition here instead of query_methods.rb
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/switchman/active_record/statement_cache.rb', line 68 def bind(values, current_shard, target_shard) bas = @bound_attributes.dup @indexes.each_with_index do |offset,i| ba = bas[offset] if ba.is_a?(::ActiveRecord::Relation::QueryAttribute) && ba.value.sharded new_value = Shard.relative_id_for(values[i], current_shard, target_shard || current_shard) else new_value = values[i] end bas[offset] = ba.with_cast_value(new_value) end bas end |
#primary_value_index ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/switchman/active_record/statement_cache.rb', line 82 def primary_value_index primary_ba_index = @bound_attributes.index do |ba| ba.is_a?(::ActiveRecord::Relation::QueryAttribute) && ba.value.primary end if primary_ba_index @indexes.index(primary_ba_index) end end |