In reply to Aleksandr Samokhin.

You can do that "loop stuff" with "select" or "use select", also you can handle that with the rest API if the "select" API isn't enough for your needs (it's common extend the rest API if you need an advanced and complex queries).