alias_attribute: handle user defined source methods#52842
Merged
byroot merged 1 commit intorails:mainfrom Sep 9, 2024
Merged
Conversation
`alias_attribute` used to define a "jump method", e.g. `alias_attribute :foo, :bar` was pretty much a macro to generate ```ruby def foo bar end ``` This is convienient because it's easy, it doesn't impose an order of declaration or anything like that. But it's also much less efficient than a true `alias_method`. It also used to cause cache size explosion which we fixed in rails#52118, but making it behave like Ruby's `alias_method`, by doing a real alias. But this breaks some expectations (literally from the documentation): ```ruby attr_accessor :name attribute_method_suffix '_short?' define_attribute_methods :name alias_attribute :nickname, :name ``` Here we're not supposed to alias a generated method, but a user defined one. So this assumption can only hold for Active Record, not Active Model.
This was referenced Sep 9, 2024
|
Are there any plans to backport this fix to 7.1.4.X? |
Member
Yes, it has already been backported to |
|
This was released in 7.1.5 and 7.2.2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Redo of: #52822
Fix: #52820
alias_attribute: handle user defined source methods
alias_attributeused to define a "jump method", e.g.alias_attribute :foo, :barwas pretty much a macro to generateThis is convienient because it's easy, it doesn't impose an order
of declaration or anything like that.
But it's also much less efficient than a true
alias_method.It also used to cause cache size explosion which we fixed in
#52118, but making it behave
like Ruby's
alias_method, by doing a real alias.But this breaks some expectations (literally from the documentation):
Here we're not supposed to alias a generated method, but a user defined one.
So this assumption can only hold for Active Record, not Active Model.