我已经建立了两个模型产品和产品价格之间的关系。该产品具有一个产品价格,并且产品价格属于该产品。但是我无法使用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̶[̶]̶>