Skip to content

Commit

Permalink
Revert "Merge pull request #52822 from byroot/active-model-alias"
Browse files Browse the repository at this point in the history
This reverts commit c0988ee.
  • Loading branch information
byroot committed Sep 9, 2024
1 parent 2cb3582 commit 9fb3c81
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
18 changes: 0 additions & 18 deletions activemodel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
* Fix regression in `alias_attribute` to work with user defined methods.

`alias_attribute` would wrongly assume the attribute accessor was generated by Active Model.

```ruby
class Person
include ActiveModel::AttributeMethods

define_attribute_methods :name
attr_accessor :name

alias_attribute :full_name, :name
end

person.full_name # => NoMethodError: undefined method `attribute' for an instance of Person
```

*Jean Boussier*

## Rails 7.2.1 (August 22, 2024) ##

Expand Down
12 changes: 1 addition & 11 deletions activemodel/lib/active_model/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,7 @@ def eagerly_generate_alias_attribute_methods(new_name, old_name) # :nodoc:
end

def generate_alias_attribute_methods(code_generator, new_name, old_name)
ActiveSupport::CodeGenerator.batch(code_generator, __FILE__, __LINE__) do |owner|
attribute_method_patterns.each do |pattern|
old_attribute_method = pattern.method_name(old_name)
if method_defined?(old_attribute_method, false)
alias_method(pattern.method_name(new_name), old_attribute_method)
else
define_attribute_method_pattern(pattern, old_name, owner: owner, as: new_name)
end
end
attribute_method_patterns_cache.clear
end
define_attribute_method(old_name, _owner: code_generator, as: new_name)
end

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

0 comments on commit 9fb3c81

Please sign in to comment.