Hi guys.. I'm lost with something that I have not seen before, I don't know if it is a bug or I'm missing something...
I have a Remote method that take an Issue Object as a parameter, the Issue Model defines a couple of properties and 2 relations, for some reason the issue argument lose the relations when arrive at the remote method. If at the client I add more objects with different names they are passed without problems (So I believe the problem is just with the relations defined in the model.json)
I have added a beforeRemote hook and at this point the relations are present on the body of the request like:
ProcessMagazine.getMagazineFileInfo {"name":"Edición Mayo","code":"EMAY2016","summary":null,"year":null,"number":null,"sku":null,"free":false,"releaseAt":"2016-05-25T03:00:00.000Z","exportedAt":null,"id":1,"magazineId":1,"createdAt":"2016-05-23T04:21:19.302Z","updatedAt":"2016-06-02T23:38:10.760Z","deletedAt":null,"_isDeleted":false,"uploadId":22,"magazine":{"name":"Parati","code":"PRTI","id":1,"publisherId":1,"createdAt":"2016-05-23T03:57:16.527Z","updatedAt":"2016-05-23T03:57:16.527Z","deletedAt":null,"_isDeleted":false},"upload":{"name":"847cb29b-843a-4a69-9931-b534f58ec903.pdf","originalName":"Polo 60 Sep-Oct.pdf","type":"application/pdf","container":"files","url":"/api/containers/files/download/847cb29b-843a-4a69-9931-b534f58ec903.pdf","id":22,"createdAt":"2016-06-02T23:38:09.164Z","updatedAt":"2016-06-02T23:38:09.164Z","deletedAt":null,"_isDeleted":false}}
and in the remote method parameter it arrives without the relations
Issue: {"name":"Edición Mayo","code":"EMAY2016","summary":null,"year":null,"number":null,"sku":null,"free":false,"releaseAt":"2016-05-25T03:00:00.000Z","exportedAt":null,"id":1,"magazineId":1,"createdAt":"2016-05-23T04:21:19.302Z","updatedAt":"2016-06-02T23:38:10.760Z","deletedAt":null,"_isDeleted":false,"uploadId":22}
module.exports = function(ProcessMagazine) {
var loopback = require('loopback');
var app = require('../../server/server');
ProcessMagazine.beforeRemote('**', function(ctx, instance, next) {
console.log(ctx.methodString, JSON.stringify(ctx.req.body));
next();
});
ProcessMagazine.getMagazineFileInfo = function(issue, cb) {
console.log('Issue: ' + JSON.stringify(issue));
var result = {
status: 200,
message: 'OK'
}
cb(null, result);
});
}
ProcessMagazine.remoteMethod(
'getMagazineFileInfo', {
accepts: [{
arg: 'issue',
type: 'Issue',
description: 'Get Magazine PDF metadata',
http: {
source: 'body'
},
required: true
}],
returns: {
arg: 'response',
type: 'object'
},
http: {
verb: 'post'
}
}
);
};
Issue Model
{
"name": "Issue",
"plural": "Issues",
"base": "PersistedModel",
"scope": {
"include": []
},
"idInjection": true,
"properties": {
"name": {
"type": "string",
"required": true
},
"code": {
"type": "string",
"required": true
},
"summary": {
"type": "string"
},
"year": {
"type": "number",
"required": false,
"length": 32
},
"number": {
"type": "string",
"required": false,
"length": 4
},
"sku": {
"type": "string",
"required": false
},
"free": {
"type": "boolean",
"required": false
},
"releaseAt": {
"type": "date",
"required": false
},
"exportedAt": {
"type": "date",
"required": false
}
},
"mixins": {
"TimeStamp": true,
"SoftDelete": true,
"Audit": {
"saveAction": true,
"deleteAction": true,
"accessAction": false
}
},
"validations": [],
"relations": {
"magazine": {
"type": "belongsTo",
"model": "Magazine",
"foreignKey": "magazineId"
},
"upload": {
"type": "belongsTo",
"model": "Upload",
"foreignKey": "uploadId"
}
},
"acls": [{
"accessType": "*",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW"
}, {
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$unauthenticated",
"permission": "DENY"
}, {
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
}, {
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
}],
"methods": {}
}
Hi guys.. I'm lost with something that I have not seen before, I don't know if it is a bug or I'm missing something...
I have a Remote method that take an Issue Object as a parameter, the Issue Model defines a couple of properties and 2 relations, for some reason the issue argument lose the relations when arrive at the remote method. If at the client I add more objects with different names they are passed without problems (So I believe the problem is just with the relations defined in the model.json)
I have added a beforeRemote hook and at this point the relations are present on the body of the request like:
ProcessMagazine.getMagazineFileInfo {"name":"Edición Mayo","code":"EMAY2016","summary":null,"year":null,"number":null,"sku":null,"free":false,"releaseAt":"2016-05-25T03:00:00.000Z","exportedAt":null,"id":1,"magazineId":1,"createdAt":"2016-05-23T04:21:19.302Z","updatedAt":"2016-06-02T23:38:10.760Z","deletedAt":null,"_isDeleted":false,"uploadId":22,"magazine":{"name":"Parati","code":"PRTI","id":1,"publisherId":1,"createdAt":"2016-05-23T03:57:16.527Z","updatedAt":"2016-05-23T03:57:16.527Z","deletedAt":null,"_isDeleted":false},"upload":{"name":"847cb29b-843a-4a69-9931-b534f58ec903.pdf","originalName":"Polo 60 Sep-Oct.pdf","type":"application/pdf","container":"files","url":"/api/containers/files/download/847cb29b-843a-4a69-9931-b534f58ec903.pdf","id":22,"createdAt":"2016-06-02T23:38:09.164Z","updatedAt":"2016-06-02T23:38:09.164Z","deletedAt":null,"_isDeleted":false}}
and in the remote method parameter it arrives without the relations
Issue: {"name":"Edición Mayo","code":"EMAY2016","summary":null,"year":null,"number":null,"sku":null,"free":false,"releaseAt":"2016-05-25T03:00:00.000Z","exportedAt":null,"id":1,"magazineId":1,"createdAt":"2016-05-23T04:21:19.302Z","updatedAt":"2016-06-02T23:38:10.760Z","deletedAt":null,"_isDeleted":false,"uploadId":22}
Issue Model