简体   繁体   中英

How to read OData association for multiple records

Let's take the Northwind odata service as an example. To get all the products of a supplier '1' I would use the following URL and in SAPUI5 it equals to: oModel.read("/Suppliers(1)/Products");

But what if I have 10 different suppliers and would like to get all products belonging to these suppliers. What is the correct way to do that? Should I loop at oModel.read("/Suppliers(X)/Products"); where X is the supplier number? Or should I use filters on the Products entity set?

You could filter Suppliers and use the $expand query attribute to include the corresponding Products into the result. This URL will return Suppliers with an ID less than 5 and their Products. As a Supplier might have a lot of products it may be better to do it the other way around, filter Products and expand the corresponding Supplier. This URL will return Products whose ID and Supplier ID are less than 5. In a real world scenario you would apply different filters, but the idea should be clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM