Skip to content

Commit b2567ea

Browse files
authored
Merge pull request rails#52822 from byroot/active-model-alias
alias_attribute: handle user defined source methods
2 parents b148081 + cfccb00 commit b2567ea

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

activemodel/lib/active_model/attribute_methods.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,17 @@ def eagerly_generate_alias_attribute_methods(new_name, old_name) # :nodoc:
215215
end
216216

217217
def generate_alias_attribute_methods(code_generator, new_name, old_name)
218-
define_attribute_method(old_name, _owner: code_generator, as: new_name)
218+
ActiveSupport::CodeGenerator.batch(code_generator, __FILE__, __LINE__) do |owner|
219+
attribute_method_patterns.each do |pattern|
220+
old_attribute_method = pattern.method_name(old_name)
221+
if method_defined?(old_attribute_method, false)
222+
alias_method(pattern.method_name(new_name), old_attribute_method)
223+
else
224+
define_attribute_method_pattern(pattern, old_name, owner: owner, as: new_name)
225+
end
226+
end
227+
attribute_method_patterns_cache.clear
228+
end
219229
end
220230

221231
def alias_attribute_method_definition(code_generator, pattern, new_name, old_name) # :nodoc:

0 commit comments

Comments
 (0)