Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue w/custom accessors + reserved name + inheritance #16458

Merged
merged 1 commit into from
Aug 17, 2014

Conversation

chancancode
Copy link
Member

Fixed an issue where custom accessor methods (such as those generated by
enum) with the same name as a global method are incorrectly overridden
when subclassing.

This was partially fixed in 4155431 then broken again by e5f15a8.

Fixes #16288.

Fixed an issue where custom accessor methods (such as those generated by
`enum`) with the same name as a global method are incorrectly overridden
when subclassing.

This was partially fixed in 4155431 then broken again by e5f15a8.

Fixes rails#16288.
@chancancode
Copy link
Member Author

@chancancode
Copy link
Member Author

Interestingly, we currently re-generate the same attribute methods on each subclass.

So, for example, if we have a "posts" table with id, title, body, and we have Event < NewsItem < Post < AR::Base, the ancestors chain would like look something this:

Event.ancestors # => [Event, GeneratedAttributeMethods(id, title, body), NewsItem, GeneratedAttributeMethods(id, title, body), Post, GeneratedAttributeMethods(id, title, body), AR::Base]

After talking to @matthewd and digging some of the git history (cc @jonleighton in case you are still interested), it seems like the intention was to move away from that and only generate them on the base class (the first non-abstract superclass). That's seems like a better long term fix, but this patch preserves the existing behaviour for the time because it seemed safer.

@chancancode chancancode added this to the 4.1.5 milestone Aug 12, 2014
@chancancode chancancode merged commit 2638d5c into rails:master Aug 17, 2014
chancancode added a commit that referenced this pull request Aug 17, 2014
Fixed issue w/custom accessors + reserved name + inheritance

Conflicts:
	activerecord/CHANGELOG.md
chancancode added a commit that referenced this pull request Aug 17, 2014
Fixed issue w/custom accessors + reserved name + inheritance

Conflicts:
	activerecord/CHANGELOG.md
@senny senny added the enum label Sep 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected behavior of AR::Enum with inherited models
3 participants