环回4如何使用有一个get方法

问题描述 投票:0回答:1

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

我认为您应该回到TypeScript问题。您正在查询beLongTo,这意味着您的响应应该是Promise<ProductPrice>而不是Promise< ̶P̶r̶o̶d̶u̶c̶t̶P̶r̶i̶c̶e̶[̶]̶>

© www.soinside.com 2019 - 2024. All rights reserved.