method
build_from_hash
Ruby on Rails latest stable (v7.1.3.2)
-
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 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1
- 5.1.7
- 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?
build_from_hash(klass, attributes, default_table)
public
Hide source
# File activerecord/lib/active_record/relation/predicate_builder.rb, line 20 def self.build_from_hash(klass, attributes, default_table) queries = [] attributes.each do |column, value| table = default_table if value.is_a?(Hash) if value.empty? queries << '1=0' else table = Arel::Table.new(column, default_table.engine) association = klass._reflect_on_association(column) value.each do |k, v| queries.concat expand(association && association.klass, table, k, v) end end else column = column.to_s if column.include?('.') table_name, column = column.split('.', 2) table = Arel::Table.new(table_name, default_table.engine) end queries.concat expand(klass, table, column, value) end end queries end