diff --git a/src/normalize.js b/src/normalize.js index 08cd1eb..1f72031 100644 --- a/src/normalize.js +++ b/src/normalize.js @@ -43,15 +43,25 @@ function extractRelationships(relationships, { camelizeKeys, camelizeTypeValues if (typeof relationship.data !== 'undefined') { if (isArray(relationship.data)) { - ret[name].data = relationship.data.map(e => ({ - id: e.id, - type: camelizeTypeValues ? camelCase(e.type) : e.type, - })); + ret[name].data = relationship.data.map((e) => { + const data = { + id: e.id, + type: camelizeTypeValues ? camelCase(e.type) : e.type, + }; + if (typeof e.meta !== 'undefined') { + data.meta = camelizeKeys ? camelizeNestedKeys(e.meta) : e.meta; + } + return data; + }); } else if (!isNull(relationship.data)) { ret[name].data = { id: relationship.data.id, type: camelizeTypeValues ? camelCase(relationship.data.type) : relationship.data.type, }; + if (typeof relationship.data.meta !== 'undefined') { + ret[name].data.meta = camelizeKeys + ? camelizeNestedKeys(relationship.data.meta) : relationship.data.meta; + } } else { ret[name].data = relationship.data; } diff --git a/test/normalize.spec.js b/test/normalize.spec.js index b0cfbf1..5000bf8 100644 --- a/test/normalize.spec.js +++ b/test/normalize.spec.js @@ -469,6 +469,62 @@ describe('relationships', () => { expect(result).to.deep.equal(output); }); + it('non-empty to-many with meta', () => { + const json = { + data: [ + { + type: 'post', + relationships: { + tags: { + data: [ + { + id: 4, + type: 'tag', + meta: { + test: 'meta value' + } + }, + ], + }, + }, + id: 2620, + attributes: { + text: 'hello', + }, + }, + ], + }; + + const output = { + post: { + 2620: { + type: 'post', + id: 2620, + attributes: { + text: 'hello', + }, + relationships: { + tags: { + data: [ + { + id: 4, + type: 'tag', + meta: { + test: 'meta value' + } + }, + ], + }, + }, + }, + }, + }; + + const result = normalize(json); + + expect(result).to.deep.equal(output); + }); + it('keys camelized', () => { const json = { data: [