Sha256: 69ed52e805b0fe398553b23cf64dbb83a22485c5a2f40042735000363e09972b

Contents?: true

Size: 1.02 KB

Versions: 17

Compression:

Stored size: 1.02 KB

Contents

module ActiveRecord
  class Relation
    class WhereClause
      silence_warnings do
        def to_h(table_name = nil)
          equalities = predicates.grep(Arel::Nodes::Equality)

          # CPK Adds this line, because ours are coming in with AND->{EQUALITY, EQUALITY}
          equalities = predicates.grep(Arel::Nodes::And).map(&:children).flatten.grep(Arel::Nodes::Equality) if equalities.empty?

          if table_name
            equalities = equalities.select do |node|
              node.left.relation.name == table_name
            end
          end

          binds = self.binds.map { |attr| [attr.name, attr.value] }.to_h

          equalities.map do |node|
            name = node.left.name
            [name, binds.fetch(name.to_s) {
              case node.right
              when Array then node.right.map(&:val)
              when Arel::Nodes::Casted, Arel::Nodes::Quoted
                node.right.val
              end
            }]
          end.to_h
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
composite_primary_keys-10.0.5 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.10 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-10.0.4 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.9 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-10.0.3 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-10.0.2 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-10.0.1 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.8 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-10.0.0 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.7 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.6 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.5 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.4 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.2 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.1 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.0 lib/composite_primary_keys/relation/where_clause.rb
composite_primary_keys-9.0.0.beta1 lib/composite_primary_keys/relation/where_clause.rb