Fix relationships request

This commit is contained in:
Aurélien Georget 2016-03-02 17:07:59 +01:00
parent 0e26dc48e9
commit 112a956bab

View File

@ -44,7 +44,7 @@ module.exports = {
}
// Fetch and format value
const value = this.fetchValue(ctx, object).toJSON() || this.fetchValue(ctx, object);
const value = this.fetchValue(ctx, object);
if (!_.isEmpty(value)) {
ctx.response.body = yield this.serialize(ctx, type, object, value, matchedRoute);
@ -295,7 +295,7 @@ module.exports = {
*/
fetchValue: function (ctx, object) {
const data = ctx.body;
const data = ctx.body.toJSON() || ctx.body;
switch (object) {
case 'collection':
@ -319,7 +319,7 @@ module.exports = {
return data[ctx.params.relation];
}
return _.first(data[ctx.params.relation]) || data[ctx.params.relation];
return data[ctx.params.relation] || _.first(data[ctx.params.relation]);
}
return null;