node.js - Loopback REST findById doesn't work well -


i'd use findbyid function through rest api.
defined "id" string constructed number.

i try find id, system seems recognize number.
can't use when id big number on "9007199254740992" - max number of integer.
i'd use id string.

please tell me how solve problem.

thank you,

--follow up--

my program follow.

model - sample-model.json

{   "name": "samplemodel",   "base": "persistedmodel",   "idinjection": true,   "properties": {     "id": {       "type": "string",       "id": "true",       "required": true,       "doc": "model id"     },     "prop1": {       "type": "string",       "required": true     }   },   "validations": [],   "relations": {},   "acls": [],   "methods": [] } 

when access findbyid function through rest api, following debug message.

  strong-remoting:shared-method - findbyid - invoke +11ms [ 9007199254740992, undefined, [function: callback] ]   strong-remoting:shared-method - findbyid - result null +25ms   strong-remoting:rest-adapter invoking rest.after samplemodel.findbyid +6ms   express:router restremotemethodnotfound  : /api/samplemodels/9007199254740993 +143ms   express:router resturlnotfound  : /api/samplemodels/9007199254740993 +8ms   express:router resterrorhandler  : /api/samplemodels/9007199254740993 +2ms   strong-remoting:rest-adapter error in /samplemodels/9007199254740993: error: unknown "samplemodel" id "9007199254740993". 

i resolved question myself.

we can define arguments remote method accepts using "accepts" option.
built-in findbyid function defines follow @ persistedmodel:

  accepts: [     { arg: 'id', type: 'any', description: 'model id', required: true,       http: {source: 'path'}},     { arg: 'filter', type: 'object',       description: 'filter defining fields , include'}   ], 

when type defined any, id changes number httpcontext.coerce function - if id consists number chars.

to solve problem, defines samplemodel.findbyidcustom , create remote method follow:

samplemodel.js

samplemodel.findbyidcustom = function(id, filter, cb) {   samplemodel.findbyid(id, filter, cb); }  //define remote method samplemodel.remotemethod(   'findbyidcustom',   {     description: 'find model instance id data source.',     accesstype: 'read',     accepts: [         { arg: 'id', type: 'string', description: 'model id', required: true,           http: {source: 'path'}},         { arg: 'filter', type: 'object',           description: 'filter defining fields , include'}     ],     returns: {arg: 'data', type: 'user', root: true},     http: {verb: 'get', path: '/:id'},     rest: {after: samplemodel.convertnulltonotfounderror},     isstatic: true   } );  //disable built-in remote method samplemethod.disableremotemethod('findbyid', true); 

thank you,


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -