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

add data option on relationships #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danivek
Copy link
Owner

@danivek danivek commented Oct 12, 2020

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');

@coveralls
Copy link

coveralls commented Oct 12, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling cc9e83d on add-data-options-for-relationships into b016d08 on master.

@danivek danivek force-pushed the add-data-options-for-relationships branch from 579e8b0 to c2db329 Compare October 12, 2020 09:11
@danivek danivek force-pushed the add-data-options-for-relationships branch from 5b313a6 to cc9e83d Compare October 12, 2020 09:32
@danivek danivek self-assigned this Oct 12, 2020
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.

2 participants