SeyZ / jsonapi-serializer

A Node.js framework agnostic library for (de)serializing your data to JSON API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't Make Relationship Work

richherbs opened this issue · comments

User Model:
image
Role Model:
image
intermediate table UserRole:
image

Role Serializer:

import jsonApi from "jsonapi-serializer";

export const roleSerializer = new jsonApi.Serializer("roles", {
  keyForAttribute: "camelCase",
  attributes: ["id", "roleName", "users"],
  users: {
    attributes: [
      "id",
      "name", 
      "email",
      "approved",
      "language",
      "createdAt",
      "updatedAt",
      "deletedAt"
    ]
  }
});

export const countryDeserializer = new jsonApi.Deserializer({
  keyForAttribute: "camelCase",
});

The instance of role serializes correctly but the relationship Users does not serialize.