📜 ⬆️ ⬇️

OData REST API - minor tricks (part 2)

We continue a series of posts about the features of using the OData protocol (see previous post ).

3. How to filter objects based on their relationships


Suppose we want to get a list of people who like a book with a title (the title property) 'book36' (we have such funny book titles in the example)

To get all the people we can write
... / persons

Easily filter data by object properties. For example, to filter people by age (the person has the age property):
... / persons? $ filter = age gt 30 - all people aged> 30 years

But how to filter by the field of another object, for example, by the name of a book that a person likes? Very simple: a person has a likes property referencing books, and a book has a title property — we can write likes / title
... / persons? $ filter = likes / title eq 'book36'



If you are interested in this post, you can also see our documentation and examples of using the REST API , as well as examples using the JavaScript library

In the next post we will talk about adding complex objects together with related objects and about adding arrays of objects.

')

Source: https://habr.com/ru/post/263167/


All Articles