Fix defect where aliased attribute methods on abstract classes were not being defined #48991
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.
Motivation / Background
This Pull Request has been created because of a defect where no methods for alias attributes defined on an abstract class are being generated.
Detail
a88f47d fixed an issue where subclasses were regenerating aliased attribute methods defined on parent classes. Part of the solution was to call
#generate_alias_attributes
recursively on a class's superclass to generate all the alias attributes in the inheritance hierarchy. However, the implementation relies on#base_class
to determine if we should call#generate_alias_attributes
on the superclass. Since all models that inherit from abstract classes are base classes, this means that#generate_alias_attributes
will never be called on abstract classes, meaning no method will be generated for any alias attributes defined on them.To fix this issue, we should always call
#generate_alias_attributes
on the superclass unless the superclass isActiveRecord::Base
.Additional information
The docs about how
base_class
work are somewhat unclear. I plan to open a separate PR to try to improve them.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]