loopbackjs - loopback 4如何使用有一个get方法
问题描述
我已经建立了两个模型产品和产品价格之间的一种关系。产品有一个产品价格,产品价格属于产品。但是我无法使用在成功实现有一个关系后添加到产品存储库的 get 方法。
这是代码
@get('/products/{id}/product-price', {
responses: {
'200': {
description: 'Array of productPrice\'s belonging to Product',
content: {
'application/json': {
schema: { type: 'array', items: getModelSchemaRef(ProductPrice) },
},
},
},
},
})
async find(
@param.path.number('id') id: number,
@param.query.object('filter') filter?: Filter<ProductPrice>,
@param.query.object('where', getWhereSchemaFor(ProductPrice)) where?: Where<ProductPrice>,
): Promise<ProductPrice[]> {
return this.productRepository.productPrices(id).get(filter) // error
}
这是错误
Type 'ProductPrice' is missing the following properties from type 'ProductPrice[]': length, pop, push, concat, and 26 more
解决方案
我认为你应该回到 TypeScript 问题。您正在查询 beLongTo 这意味着您的回答应该是Promise<ProductPrice>
而不是Promise< ̶P̶r̶o̶d̶u̶c̶t̶P̶r̶i̶c̶e̶[̶]̶>
推荐阅读
- git - bash: atom: command not found 如何在 Windows 中解决这个问题?
- mongodb - 如何永久设置 mongo db 路径
- python - Scrapy连续运行而不是同时运行
- android - 生成签名的 APK
- mysql - Mysql选择行,更新值并插入另一个表
- python-3.x - 使用create_task() 还是gather() 效率更高?
- python - 用 PRAW 制作一个机器人。似乎忽略了一些人?
- android - 无法在 android gradle 文件末尾应用插件
- kubernetes - 在 MiniKube K8S 中部署 PV
- javascript - PHP Xpath JS如何使用JS从站点获取内容?