Skip to content

Commit a23a0c7

Browse files
committed
Ignore included record's relationships
Avoid the situation described here: danivek/json-api-serializer#10
1 parent 2f91110 commit a23a0c7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/api/services/JsonApiService.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ module.exports = {
129129
serialize: function(modelName, data) {
130130

131131
var returnedValue = Serializer.serialize(modelName, data);
132+
133+
/*
134+
* To avoid the situation where many to many relationships are not described both ways
135+
* let's remove all included record's relationships
136+
* See https://github.com/danivek/json-api-serializer/issues/10 for more information
137+
*/
138+
if (returnedValue.included) {
139+
returnedValue.included.forEach((include) => {
140+
delete include.relationships;
141+
});
142+
}
132143
delete returnedValue.jsonapi; // Let's ignore the version for now
133144

134145
return returnedValue;

tests/dummy/test/integration/controllers/Relationships.test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ describe("Has many through relationships", function() {
124124
"id": houseId,
125125
"attributes": {
126126
"city": "Paris"
127-
},
128-
"relationships": {
129-
"pets": {
130-
"data": []
131-
}
132127
}
133128
}]
134129
})

0 commit comments

Comments
 (0)