How to specify Strongloop model schema?

怎甘沉沦 提交于 2019-12-12 04:18:33

问题


I try override find api of strongloop rest endpoint. I want to return an array of objects. But how do I specify the schema for the object? As you can see from the picture above, the model schema is empty.

Below is the code of my company model remoteMethod:

    Company.remoteMethod(
        'find',
        {
            accepts: {arg: 'msg', type: 'string'},
            returns: {type: 'array', root: true},
            http: {path: '/', verb:'get'}
        }
    )

回答1:


If I understand you right, your'e trying to show at this section the returned model as follows:

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

In order to achieve this kind of return type representation, you need to define your return type in remoteMethod options to be an array of the desired model.

Here is your code, with the required edit, using modelName propery of Model base class:

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


来源:https://stackoverflow.com/questions/34984027/how-to-specify-strongloop-model-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!