Search code examples
apireststrapi

Strapi LEFT JOIN two Tables


It's my first experience with Strapi. I'm Flutter developer. I want to make API for my App. I need join two tables in one API request. I have table1 and table2 witch has link with users.

It should works like this:

SELECT * FROM table1
LEFT JOIN (SELECT * FROM table2 WHERE userId = myId) AS tab2 On table1.id = tab2.id;

Is there already method in Strapi (4.3.8) or I need to make this myself?

I know about relationship. I can make this request:

/api/words?populate=user_words

But I need to select user_words only for my user, not all users as it works now.


Solution

  • Just combine it with the filters param, e.g:

    /api/words?populate=user_words&filters[user_id][$eq]=1234

    More on that: https://docs.strapi.io/dev-docs/api/rest/filters-locale-publication#filtering.