0

let's say I have Order model that hasMany Product(product_id, name, order_id) and Product belongs to Order

I want to find only those orders that have product with specific product_id.

According to https://loopback.io/doc/en/lb3/Include-filter.html this should work, but it doesn't

getOrders?filter={"include":{"relation":"Product","scope":{"where":{"product_id":"6"}}}}

that kid of filter shows all orders no matter if it has product with id 6 or not.

where do I go wrong?

1 Answer 1

2

Your query should show you all orders, but it will include only products that id fits your requirements. But it may depend on db connector you're using. Based on what you've wrote I guess it's mongo, so it's not possible.

Instead, you could turn around the query and look for products where product_id is 6 and include order relation. So the query would look like this:

getProducts?filter={"where": {"product_id": 6}, "include": "orders"}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.