How to specify the scheme of the Strongloop model?

enter image description here

I am trying to override find api strongloop breakpoint. I want to return an array of objects. But how to specify a schema for an object? As can be seen from the figure above, the model diagram is empty.

The following is the code for my remoteMethod company model:

Company.remoteMethod( 'find', { accepts: {arg: 'msg', type: 'string'}, returns: {type: 'array', root: true}, http: {path: '/', verb:'get'} } ) 
0
loopbackjs strongloop
source share
1 answer

If I understand you correctly, you are trying to show the returned model in this section as follows:

 [ { "companyProperty1": "companyProperty1Type", "companyProperty2": "companyProperty2Type", . . "companyPropertyN": "companyPropertyNType", } ] 

To get such a representation of the return type, you need to define the return type in the remoteMethod parameters as an array of the desired model.

Here is your code with the required editing, using modelName propertyy for the base class Model :

 Company.remoteMethod( 'find', { accepts: {arg: 'msg', type: 'string'}, returns: {type: [Company.modelName], root: true}, http: {path: '/', verb:'get'} } ) 
+3
source share

All Articles