loopback 4, как использовать, имеет один метод получения

Я установил одно соотношение между двумя моделями товара и ценами на товар. У продукта одна цена продукта, и цена продукта принадлежит продукту. Но я не могу использовать метод 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

person pratik jaiswal    schedule 23.04.2020    source источник
comment
Вы уверены, что get(filter) в отношении репозитория? Разве не должно быть find(filter) ??   -  person Salitha    schedule 23.04.2020
comment
find () для имеет много отношений. Есть ли у одного ()   -  person pratik jaiswal    schedule 24.04.2020


Ответы (1)


Думаю, вам следует вернуться к проблеме TypeScript. Вы запрашиваете beLongTo, что означает, что ваш ответ должен быть Promise<ProductPrice>, а не Promise< ̶P̶r̶o̶d̶u̶c̶t̶P̶r̶i̶c̶e̶[̶]̶>

person Dat Ho    schedule 23.04.2020