aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb10
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb4
2 files changed, 12 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 986a7ade81..d4d592bbbf 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -218,6 +218,16 @@ module ActiveModel
end
end
+ # Is +new_name+ an alias?
+ def attribute_alias?(new_name)
+ attribute_aliases.key? new_name.to_s
+ end
+
+ # Returns the original name for the alias +name+
+ def attribute_alias(name)
+ attribute_aliases[name.to_s]
+ end
+
# Declares the attributes that should be prefixed and suffixed by
# ActiveModel::AttributeMethods.
#
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index b7609c97b5..57b7e8d13d 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -6,8 +6,8 @@ module ActiveRecord
attributes.each do |column, value|
table = default_table
- if column.is_a?(Symbol) && klass.attribute_aliases.key?(column.to_s)
- column = klass.attribute_aliases[column.to_s]
+ if column.is_a?(Symbol) && klass.attribute_alias?(column)
+ column = klass.attribute_alias(column.to_s)
end
if value.is_a?(Hash)