method
create_binds_for_hash

v5.1.7 -
Show latest stable
-
0 notes -
Class: ActiveRecord::PredicateBuilder
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
create_binds_for_hash(attributes)
protected
Hide source
# 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