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

Polymorphic has_one and has_many doesn't respect custom polymorphic_name #437

Open
jasonkarns opened this issue Oct 5, 2022 · 0 comments

Comments

@jasonkarns
Copy link
Contributor

jasonkarns commented Oct 5, 2022

Rails uses .polymorphic_name to derive the value for the {association}_type attribute value. It's fairly common, if not documented/supported, to override polymorphic_name for AR Models that need to store or support custom translations between the attribute value and ruby class names.

Unfortunately, Graphiti::Adapters::Persistence::Associations directly emits the ruby class name for the _type attribute without consulting polymorphic_name.

attrs[:"#{x[:sideload].polymorphic_as}_type"] = parent_object.class.name

Luckily, this behavior lives on the adapter, so it can be overridden. However, I would like to push this into the AR adapter so that the rails adapter more closely follows Rails' own behavior.

I think my proposal would be for the Assocations 'base' adapter to have a polymorphic_name method which evaluates to class.name, thus allowing the AR adapter to override as class.polymorphic_name. Unless anyone sees any reason for this to be something that lives on the resource or resource proxy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant