method
create_binds_for_hash
rails latest stable - Class:
ActiveRecord::PredicateBuilder
create_binds_for_hash(attributes)protected
No documentation available.
# File activerecord/lib/active_record/relation/predicate_builder.rb, line 85
def create_binds_for_hash(attributes)
result = attributes.dup
binds = []
attributes.each do |column_name, value|
case
when value.is_a?(Hash) && !table.has_column?(column_name)
attrs, bvs = associated_predicate_builder(column_name).create_binds_for_hash(value)
result[column_name] = attrs
binds += bvs
next
when value.is_a?(Relation)
binds += value.bound_attributes
when value.is_a?(Range) && !table.type(column_name).force_equality?(value)
first = value.begin
last = value.end
unless first.respond_to?(:infinite?) && first.infinite?
binds << build_bind_param(column_name, first)
first = Arel::Nodes::BindParam.new
end
unless last.respond_to?(:infinite?) && last.infinite?
binds << build_bind_param(column_name, last)
last = Arel::Nodes::BindParam.new
end
result[column_name] = RangeHandler::RangeWithBinds.new(first, last, value.exclude_end?)
else
if can_be_bound?(column_name, value)
result[column_name] = Arel::Nodes::BindParam.new
binds << build_bind_param(column_name, value)
end
end
# Find the foreign key when using queries such as:
# Post.where(author: author)
#
# For polymorphic relationships, find the foreign key and type:
# PriceEstimate.where(estimate_of: treasure)
if table.associated_with?(column_name)
result[column_name] = AssociationQueryHandler.value_for(table, column_name, value)
end
end
[result, binds]
end