scoutforpets / jsonapi-mapper

JSON API-Compliant Serialization for your Node ORM
The Unlicense
42 stars 24 forks source link

ability to include/exclude relation data in payload (fixes #63) #65

Closed jamesdixon closed 8 years ago

jamesdixon commented 8 years ago

This PR fixes #63 by allowing an included attribute to be specified as part of the relations option. Previously, the relations option was either a boolean or an array of strings. This has now been changed to either a boolean or an object containing options that determine how a relationship is processed.

The array of relation names has now been moved into a fields property. Example:

relations: {
  fields: ['rel1', 'rel2']
}

The new syntax also allows for an included option to determine whether the relation data is included as a compound document, which has been the default thus far. Setting included: false will not include the actual relation data in the payload.

Scenarios:

relations : true // all in, to maintain the current behaviour
relations : false // nothing
relations : { included: true } // relation data included in payload
relations : { included: false } // relations defined, but data not included in payload
jamesdixon commented 8 years ago

@chamini2 @ShadowManu would love your feedback on this.

jamesdixon commented 8 years ago

Note that I haven't updated the README yet, but will do so after getting your feedback.

jamesdixon commented 8 years ago

@chamini2 thanks for the thorough review. I just pushed a few fixes from above.

jamesdixon commented 8 years ago

If you're good with the changes, LGTM 👍

jamesdixon commented 8 years ago

1.0.0-beta.4 is live