0

I am using Loopback3.

Is there a proper way of getting related values without having to nest them?

The following code is just a sample for an idea that I would like to happen:

function getRelatedModel(){
    var items;
    relatedModel.find({}, function(err,res){
        items = res;
    });
    return items;
}
//OR
var items = relatedModel.find();
Mark Ryan Orosa
  • 847
  • 1
  • 6
  • 21
  • 2
    Pretty much described the exact use case for promises. Take a look at [this question](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – CRice Apr 03 '18 at 01:29
  • thank you for the reply, but I was hoping to avoid that, maybe there is a way of doing queries in Loopback in such away we dont have to initiate a callback. Will update my post. – Mark Ryan Orosa Apr 03 '18 at 01:55
  • 1
    loopback supports promises. `relatedModel.find({}).then(res => {}) –  Apr 03 '18 at 14:30

0 Answers0