0

How to connect models created in loopback and fetch the associated data?

configuration:

model1 *has many* model2
model2 *belongs to* model1

I did build has many using slc loopback:relation and the model1 and model2 are connected but failed to show the associated model2 while displaying the model1 contents.

Any suggestion? Thanks in advance.

chicks
  • 2,393
  • 3
  • 24
  • 40
Vinay
  • 548
  • 2
  • 12

1 Answers1

2

You haven't shown any code, but I suspect that you are not including model2 in your query. You need to instruct LoopBack to include related models.

Node.js

model1.find({include: 'model2'}, function() { ... });

REST

model1?filter[include]=model2

https://docs.strongloop.com/display/public/LB/Include+filter

duffn
  • 3,690
  • 8
  • 33
  • 68