Skip to content

Commit

Permalink
Fix relationship link for has many
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Molinié committed Oct 15, 2018
1 parent 39b27de commit 12de3c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/serializers/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ function ResourceSerializer(Implementation, model, records, integrator, opts, me
this.perform = function () {
var typeForAttributes = {};

function getRelatedLinkForHasMany(modelName, relationshipName, idField) {
function getRelatedLinkForHasMany(modelName, relationshipName) {
return function (record, current, parent) {
if (current && current[relationshipName]) {
return null;
}
return `/forest/${modelName}/${parent[idField]}/relationships/${relationshipName}`;
return `/forest/${modelName}/${parent.id}/relationships/${relationshipName}`;
};
}

Expand Down Expand Up @@ -106,7 +106,7 @@ function ResourceSerializer(Implementation, model, records, integrator, opts, me
const modelName = Implementation.getModelName(model);
const relatedFunction = field.relationship === 'BelongsTo'
? null
: getRelatedLinkForHasMany(modelName, field.field, schema.idField);
: getRelatedLinkForHasMany(modelName, field.field);
dest[fieldName] = {
ref: fieldReference,
nullIfMissing: true,
Expand Down

0 comments on commit 12de3c3

Please sign in to comment.