pratik jaiswal
pratik jaiswal

Reputation: 2065

loopback 4 how to use has one get method

I have set up has one relation between two models product and product-prices. The product has one product-price and product-price belongs to the product. But I am unable to use get method that is been added to product repository after successful implementation of has one relation.

Here is the code

@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
  }

here is the error

Type 'ProductPrice' is missing the following properties from type 'ProductPrice[]': length, pop, push, concat, and 26 more

Upvotes: 0

Views: 137

Answers (1)

Dat Ho
Dat Ho

Reputation: 742

I think you should get back to TypeScript problem. You are querying beLongTo that mean your response should be Promise<ProductPrice> and not Promise< ̶P̶r̶o̶d̶u̶c̶t̶P̶r̶i̶c̶e̶[̶]̶>

Upvotes: 1

Related Questions