Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/deserializer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

var _ = require('lodash')
var utils = require('./utils')

function defaultBeforeDeserialize (options, cb) {
cb(null, options)
Expand Down Expand Up @@ -78,6 +79,17 @@ function belongsToRelationships (options) {
if (!relationship.data) {
options.result[fkName] = null
} else {
// https://github.com/digitalsadhu/loopback-component-jsonapi/compare/master...grahambates:loopback-component-jsonapi:master
if (serverRelation.polymorphic) {
var relatedType = relationship.data.type
var modelClass = _.find(model.app.models, function (model) {
var plural = utils.pluralForModel(model)
return plural === relatedType
})

var discriminator = serverRelation.polymorphic.discriminator
options.result[discriminator] = modelClass.modelName
}
options.result[fkName] = relationship.data.id
}
})
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities/relationship-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getInvalidIncludesError (message) {
}

function isLoopbackInclude (ctx) {
return ctx.args && ctx.args.filter
return ctx.args && ctx.args.filter && ctx.args.filter.include
}

function isJSONAPIInclude (req) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function setRequestedIncludes (include) {
}

if (inc instanceof Object) {
return inc.relation
return inc.relation || _.findKey(inc, value => value === true)
}
})
}
Expand Down