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

Allow customizing the type of polymorphic association #2484

Open
wants to merge 1 commit into
base: 0-10-stable
Choose a base branch
from

Conversation

klaaspieter
Copy link

Purpose

Allow customizing the type of polymorphic association. We needed this because in our codebase we have model names that we'd like to change but we cannot without also doing the necessary database migrations. It hasn't been a priority yet but we want our new API to use the new naming already.

Changes

Read the json_key from the association serializer when determining the polymorphic type to use. This changes the JSON serialization:

{
  id: 1,
  title: 'headshot-1.jpg',
  imageable: {
-    type: 'employee',
-    employee: {
+   type: 'custom',
+   custom: {
      id: 42,
      name: 'Zoop Zoopler'
    }
  }
}

Caveats

This is a breaking change. I'd love to hear how this change can be introduced in a way that is least disruptive.

Related GitHub issues

I think #2131 is related

Additional helpful information

n.a.

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

Successfully merging this pull request may close these issues.

1 participant