Skip to content

Polymorphic relationships not serialized correctly #1748

@Turbo87

Description

@Turbo87

I'm using the ActiveModelSerializer and I have defined a polymorphic relationship in one of my models:

export default Model.extend({
  subject: belongsTo({ polymorphic: true }),
});

When I try to serialize a Collection of that model I would expect plain subject_id and subject_type attributes, but instead I get a subject_id attribute that consists of a JSON object with id and type attributes.

I've traced this down to a potential bug in _maybeAddAssociationIds() of the Serializer base class. It looks like for serializeIds === "included" there is a special case for association.isPolymorphic, but for this.serializeIds === "always" the same case is missing. Since the rest of the implementation looks similar I would assume that copy-pasting the existing special case in the other branch would solve my problem 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions