Skip to content

Commit

Permalink
Relationship data can be items or empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichar1 committed Feb 9, 2024
1 parent 20716c1 commit 3e3c058
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pinia-jsonapi",
"version": "6.3.0",
"version": "6.4.0",
"description": "Access restructured JSONAPI data from a Pinia Store.",
"author": "Matthew Richardson <[email protected]>",
"scripts": {
Expand Down
15 changes: 11 additions & 4 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,22 @@ const actions = (api, conf, utils) => {
let res = get(data, ['data'])
let included = get(data, ['included'])
if (res) {
allRels.push(res)
// Convert items to collections
if (!Array.isArray(res)) {
res = [res]
}
allRels.push(...res)
}
if (included) {
allRels.push(...included)
}
// Restructure the data
let norm = utils.jsonapiToNorm(allRels)

Object.assign(allNorm, norm)
let norm = {}
if (allRels.length) {
norm = utils.jsonapiToNorm(allRels)
Object.assign(allNorm, norm)
}
// Always set at least { relName: {} } to indicate empty rels
merge(allRelated, { [relName]: norm })
})
this.mergeRecords(allNorm)
Expand Down

0 comments on commit 3e3c058

Please sign in to comment.