-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Delegated Type supports customizeable foreign_type column #45041
Conversation
8307e96
to
09ef9b2
Compare
Can you add a CHANGELOG entry in Active Record? The change makes sense to me |
edda66e
to
d245e6d
Compare
@skipkayhil Added changelog entry and rebased. I assume the entry was supposed to go at the top. (I looked at its git-blame and most recent entries seemed to be at the top) Happy to reword as desired. |
cbc5a26
to
f68db84
Compare
f68db84
to
f1f2390
Compare
@skipkayhil rebased. any chance this can land in 7.1? Our team has an ugly monkey patch dealing with this right now. |
It just needs to be reviewed by a committer. I'll see if I can get it some attention in the Discord |
@jasonkarns can you add a test for this? |
5af9f51
to
23f8409
Compare
@eileencodes tests added. I can squash/rebase again if necessary but wanted eyes on the tests before I do that. I'm not super familiar with the AR test suite opinions or patterns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple comments about documentation/changelog. Otherwise this looks good. Let me know when you've rebased and squashed your commits. The changelog entry goes at the top of the file when fixing the conflict.
d6eb1db
to
1f61fd6
Compare
@eileencodes rebased! |
Adds support for customizing
delegated_type
's{role}_type
column via theforeign_type
option.Summary
Delegated Types leans heavily on Rails’ existing polymorphic associations. The primary association created by
delegated_type
is a polymorphicbelongs_to
association.For apps that are using polymorphic associations but need to customize the column containing the type/class,
foreign_type
is available as an option. It would be helpful if the same customization were available for Delegated Types.Since delegated_types already passes its options along to the underlying belongs_to association, this is a relatively straightforward change. Instead of only deriving the type column by using "#{role}_type", it can respect a
foreign_type
option. (Same option key as used by polymorphic associations.)Example: