0

I have three models product, purchase, and stocks. The product mode has hasmany relation with purchase and stock. Now I want to collect data from all three models. Recently Loopback team added inclusion resolvers for has many relations https://loopback.io/doc/en/lb4/HasMany-relation.html#querying-related-models. But still, there is no support to include related models. Now how can I get data from these three models

pratik jaiswal
  • 1,855
  • 9
  • 27
  • 59

1 Answers1

0

Recently loopback team added the feature of inclusion resolver. Stepwise procedure to use it in your project. 1. Update loopback with the command npm i @loopback/cli --save 2. If you are creating a new project you can add inclusion resolver while generating relation using lb4 relation command. It will ask you whether you want to include model to another model type "yes". 3. For old project add this line in source model's repository.ts file

this.registerInclusionResolver('orders', this.orders.inclusionResolver);

where 'orders' is the name of the relation

for example, customers have has-many relation with orders Now you can include these two models on the following the extension

  http://localhost:3000/customers?filter[include][][relation]=orders

referencelink

pratik jaiswal
  • 1,855
  • 9
  • 27
  • 59