Be able to use the $select-statement inside an $expand-EntitySet with the OData v4/OData v3 - Mendix Forum

Be able to use the $select-statement inside an $expand-EntitySet with the OData v4/OData v3

9

When you have an OData API-layer on top of your Mendix database, you can work with the following options documented by Mendix: https://docs.mendix.com/refguide/odata-query-options/

 

Specifically for the $expand-option in the URL to navigate to an associated entity, Mendix supports up to the following URL’s:

Associated objects can be retrieved by passing the $expand query parameter. For example: /odata/myservice/v1/Employees?$expand=Cars,Address($expand=City) (OData 4) or /odata/myservice/v1/Employees?$expand=Cars,Address/City (OData 3).

 

In the above example, I will get the Employee-entity with all of its attributes, the associated Car-entity with all of its attributes, the associated Address-entity and all of its attributes, together with the associated City-entity and all of its attributes.

 

However, I want to have the flexibility to only select the attribute(s) of the associated entity/entities that I need. Not all of them. Which would result in the following (according to official OData.org documentation):

/odata/myservice/v1/Employees?$expand=Cars($select=BrandName),Address($expand=City($select=ZipCode)) (OData v4)

In this example, I’d like to have the Employee-entities with a column for their car’s brandname and the zipcode of their city. Basically, just two columns instead of everything of the car- and city-attributes.

I would advise to have the same option for OData v3.

 

Thank you!

 

Kind regards,

Leander

asked
0 answers