Skip to content

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