json-api-serializer
json-api-serializer copied to clipboard
add data option on relationships
Add a data option function that returns the data to serialize for the relationship.
Example:
Input data can contains meta information ( e.g. total) on data for a relationship.
{
"id": "1",
"title": "article 1",
"comments": {
"total": 2,
"data": [
{
"id": "1",
"title": "comment 1"
},
{
"id": "2",
"title": "comment 2"
}
]
}
}
Add a data option as a function to return data to serialize for the relationship:
const Serializer = new JSONAPISerializer();
Serializer.register('article', {
relationships: {
comments: {
type: 'comment',
data: (input) => input.data
}
}
});
Serializer.register('comment');