Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData Filter for child and return parent

Tags:

odata

olingo

I am developing a search function which will be powered by a OData service. It will return one or a list of Header Objects as results. Many fields that we need to search on are not in the Header Object. They are only in child Objects(Navigational Properties). What is the right approach to be able to execute an OData search against a child field and still return the parent object list.

This is similar to what I would expect to be able to do in standard SQL as an 'exists' query.

I am using Java - Apache Olingo for my project but I believe that this is a general OData question.

like image 932
Chaim Avatar asked Sep 29 '25 09:09

Chaim


2 Answers

Yes this is perfectly possible, just include the child path in the $filter

e.g. say we have a header Aircraft and child Airline

/Aircraft would list all aircraft for all Airlines Aircraft?$filter=Airline/Code eq 'BA' would list all Aircraft for BA only

For you 2nd query, to return the child and filter on the parent... Not sure about returning JUST the child - you can do this if you resolve to a single parent by its key, e.g. Aircraft(123)/Airline - would find Aircraft with key 123 and return JUST the airline child navigation property info

to filter and include multiple headers, then I think your only option is to use $expand to include the child info with the header info. e.g.

Aircraft?$filter=BodyType eq 'NB'&$expand=Airline - so this filters the header aircraft on type NB (narrow body), and includes the child Airline info along with it.

Hope this helps.

like image 192
Mark Bennetts Avatar answered Oct 02 '25 04:10

Mark Bennetts


If it is about OData protocl itself, this is supported like: Address/City eq 'Redmond' Address/City ne 'London' (http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398301)

when it comes to the implementation in Apache Olingo, you can ask questions in its mailing list: [email protected] . and you can follow http://olingo.apache.org/support.html to join the discussion list.

like image 25
challenh Avatar answered Oct 02 '25 06:10

challenh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!