Sha256: ac0263ec4caadba5b387e82373e69bb617b1f7d3318e771a55034cb5fa1b631b

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

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
          predicates = where_clause.send(:predicates)
          @scope.send(:infer_shards_from_primary_key, predicates, where_clause.binds) if @scope.shard_source_value == :implicit && @scope.shard_value.is_a?(Shard)
          predicates = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, where_clause.binds) if @scope.shard_source_value != :explicit
          where_clause.instance_variable_set(:@predicates, predicates)
          where_clause
        else
          super
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
switchman-1.6.0 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.21 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.20 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.19 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.18 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.17 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.16 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.15 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.14 lib/switchman/active_record/where_clause_factory.rb
switchman-1.5.13 lib/switchman/active_record/where_clause_factory.rb