Sha256: 2569ef6208a18afcc020f5cf28f3b217d90ef9c45a37e2df4fc9681f59f5a9d0
Contents?: true
Size: 1.25 KB
Versions: 22
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module Switchman module ActiveRecord module WhereClauseFactory attr_writer :scope def build(opts, other = []) case opts when String, Array values = Hash === other.first ? other.first.values : other values.grep(ActiveRecord::Relation) do |rel| # serialize subqueries against the same shard as the outer query is currently # targeted to run against if rel.shard_source_value == :implicit && rel.primary_shard != @scope.primary_shard rel.shard!(@scope.primary_shard) end end super when Hash, ::Arel::Nodes::Node where_clause = super binds = ::Rails.version >= "5.2" ? nil : where_clause.binds predicates = where_clause.send(:predicates) @scope.send(:infer_shards_from_primary_key, predicates, binds) if @scope.shard_source_value == :implicit && @scope.shard_value.is_a?(Shard) predicates, _new_binds = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, binds: binds) where_clause.instance_variable_set(:@predicates, predicates) where_clause else super end end end end end
Version data entries
22 entries across 22 versions & 1 rubygems