aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/attribute_methods.rb
diff options
context:
space:
mode:
authorMaximilian Schneider <mail@maximilianschneider.net>2012-06-22 16:44:01 +0200
committerMaximilian Schneider <mail@maximilianschneider.net>2012-06-22 16:44:01 +0200
commitf984b8152fb497919b30c9c96e471e0736f3a6d2 (patch)
tree7d8d56d7e662157a2b6c7c965c42263ebdda5a97 /activemodel/lib/active_model/attribute_methods.rb
parent323ee207cbbcd66574045ebedd30765da10d3f6f (diff)
downloadrails-f984b8152fb497919b30c9c96e471e0736f3a6d2.tar.gz
rails-f984b8152fb497919b30c9c96e471e0736f3a6d2.tar.bz2
rails-f984b8152fb497919b30c9c96e471e0736f3a6d2.zip
made dynamic finders alias_attribute aware
previously dynamic finders only worked in combination with the actual column name and not its alias defined with #alias_attribute
Diffstat (limited to 'activemodel/lib/active_model/attribute_methods.rb')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index b5b50847c2..30f51e041f 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -61,7 +61,8 @@ module ActiveModel
CALL_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?]?\z/
included do
- class_attribute :attribute_method_matchers, instance_writer: false
+ class_attribute :attribute_aliases, :attribute_method_matchers, instance_writer: false
+ self.attribute_aliases = {}
self.attribute_method_matchers = [ClassMethods::AttributeMethodMatcher.new]
end
@@ -192,6 +193,7 @@ module ActiveModel
# person.nickname # => "Bob"
# person.name # => "Bob"
def alias_attribute(new_name, old_name)
+ self.attribute_aliases = attribute_aliases.merge(new_name.to_s => old_name.to_s)
attribute_method_matchers.each do |matcher|
matcher_new = matcher.method_name(new_name).to_s
matcher_old = matcher.method_name(old_name).to_s