ray
ray

Reputation: 5552

Get Associated Data For LoopBack 4

I have User & Address tables & models, for users I have ids [23, 45, 54] & I want to fetch Addresses for those users.

What will be best practice to fetch data?

I was trying somewhat like,

userRepository.find({
  where: [23, 45, 54],
  includes: [{relation: 'address'}]
})

Above will not work, I know as I am new to this loopback 4 & did not work with exception.

Upvotes: 1

Views: 75

Answers (1)

Nikos Oikonomou
Nikos Oikonomou

Reputation: 196

You are using where filter incorrectly, the where filter should be an object. For example if you want to find all the users with a property that equals one of the values 23, 45 or 54 then you should so something like this:

userRepository.find({
  where: { propertyYouWantToMatch: { inq: [23, 45, 54] }
  ...
}); 
  

Official 'inq' examples

Resources to read:

Upvotes: 1

Related Questions