method
build_where_clause
v8.0.0 -
Show latest stable
- Class:
ActiveRecord::QueryMethods
build_where_clause(opts, rest = [])protected
No documentation available.
# File activerecord/lib/active_record/relation/query_methods.rb, line 1613
def build_where_clause(opts, rest = []) # :nodoc:
opts = sanitize_forbidden_attributes(opts)
if opts.is_a?(Array)
opts, *rest = opts
end
case opts
when String
if rest.empty?
parts = [Arel.sql(opts)]
elsif rest.first.is_a?(Hash) && /:\w+/.match?(opts)
parts = [build_named_bound_sql_literal(opts, rest.first)]
elsif opts.include?("?")
parts = [build_bound_sql_literal(opts, rest)]
else
parts = [model.sanitize_sql(rest.empty? ? opts : [opts, *rest])]
end
when Hash
opts = opts.transform_keys do |key|
if key.is_a?(Array)
key.map { |k| model.attribute_aliases[k.to_s] || k.to_s }
else
key = key.to_s
model.attribute_aliases[key] || key
end
end
references = PredicateBuilder.references(opts)
self.references_values |= references unless references.empty?
parts = predicate_builder.build_from_hash(opts) do |table_name|
lookup_table_klass_from_join_dependencies(table_name)
end
when Arel::Nodes::Node
parts = [opts]
else
raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
end
Relation::WhereClause.new(parts)
end