class method
self.expand_hash_conditions_for_aggregates
Ruby on Rails 3.1.12
Since v2.2.3 Last seen in v3.1.12Signature
self.expand_hash_conditions_for_aggregates(attrs)
Accepts a hash of SQL conditions and replaces those attributes that correspond to a composed_of relationship with their expanded aggregate attribute values. Given:
class Person < ActiveRecord::Base composed_of :address, :class_name => "Address", :mapping => [%w(address_street street), %w(address_city city)] end
Then:
{ :address => Address.new("813 abc st.", "chicago") }
# => { :address_street => "813 abc st.", :address_city => "chicago" }
Parameters
-
attrsreq
Source
# File activerecord/lib/active_record/base.rb, line 1411
def expand_hash_conditions_for_aggregates(attrs)
expanded_attrs = {}
attrs.each do |attr, value|
unless (aggregation = reflect_on_aggregation(attr.to_sym)).nil?
mapping = aggregate_mapping(aggregation)
mapping.each do |field_attr, aggregate_attr|
if mapping.size == 1 && !value.respond_to?(aggregate_attr)
expanded_attrs[field_attr] = value
else
expanded_attrs[field_attr] = value.send(aggregate_attr)
end
end
else
expanded_attrs[attr] = value
end
end
expanded_attrs
end
Defined in activerecord/lib/active_record/base.rb line 1411
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base