Skip to content
Browse files

de-globalise method

  • Loading branch information...
1 parent 75a2281 commit 4bd9482a1a890c50264b4a9320e6853f1a0bde69 @jonleighton jonleighton committed May 3, 2012
View
9 activerecord/lib/active_record/dynamic_matchers.rb
@@ -63,9 +63,7 @@ def initialize(model, name)
def expand_attribute_names_for_aggregates
attribute_names.map do |attribute_name|
if aggregation = model.reflect_on_aggregation(attribute_name.to_sym)
- model.send(:aggregate_mapping, aggregation).map do |field_attr, _|
- field_attr.to_sym
- end
+ aggregation.mapping.map { |m| m.first.to_sym }
else
attribute_name.to_sym
end
@@ -240,10 +238,5 @@ def instantiator
"create!"
end
end
-
- def aggregate_mapping(reflection)
- mapping = reflection.options[:mapping] || [reflection.name, reflection.name]
- mapping.first.is_a?(Array) ? mapping : [mapping]
- end
end
end
View
4 activerecord/lib/active_record/reflection.rb
@@ -153,6 +153,10 @@ def derive_class_name
# Holds all the meta-data about an aggregation as it was specified in the
# Active Record class.
class AggregateReflection < MacroReflection #:nodoc:
+ def mapping
+ mapping = options[:mapping] || [name, name]
+ mapping.first.is_a?(Array) ? mapping : [mapping]
+ end
end
# Holds all the meta-data about an association as it was specified in the
View
2 activerecord/lib/active_record/sanitization.rb
@@ -58,7 +58,7 @@ def expand_hash_conditions_for_aggregates(attrs)
expanded_attrs = {}
attrs.each do |attr, value|
if aggregation = reflect_on_aggregation(attr.to_sym)
- mapping = aggregate_mapping(aggregation)
+ mapping = aggregation.mapping
mapping.each do |field_attr, aggregate_attr|
if mapping.size == 1 && !value.respond_to?(aggregate_attr)
expanded_attrs[field_attr] = value

0 comments on commit 4bd9482

Please sign in to comment.
Something went wrong with that request. Please try again.