Object
# File lib/active_record/relation/predicate_builder.rb, line 8
8: def build_from_hash(attributes, default_table)
9: predicates = attributes.map do |column, value|
10: table = default_table
11:
12: if value.is_a?(Hash)
13: table = Arel::Table.new(column, :engine => @engine)
14: build_from_hash(value, table)
15: else
16: column = column.to_s
17:
18: if column.include?('.')
19: table_name, column = column.split('.', 2)
20: table = Arel::Table.new(table_name, :engine => @engine)
21: end
22:
23: attribute = table[column] || Arel::Attribute.new(table, column)
24:
25: case value
26: when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation
27: values = value.to_a.map { |x|
28: x.respond_to?(:quoted_id) ? x.quoted_id : x
29: }
30: attribute.in(values)
31: when Range, Arel::Relation
32: attribute.in(value)
33: when ActiveRecord::Base
34: attribute.eq(value.quoted_id)
35: when Class
36: # FIXME: I think we need to deprecate this behavior
37: attribute.eq(value.name)
38: else
39: attribute.eq(value)
40: end
41: end
42: end
43:
44: predicates.flatten
45: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.