Doubts about the best way to search for data according to my objective

I’m creating an app on WeWeb with Supabase. I want to search for publications created by the user to make up their public profile, and display them in a list component, so far without any problems for me.

Now for each line in the list, which displays the posts, I want to look for the comments on the post.

I have the “post” table with the “post_id” field, and the other fields. And I have the “commentary” table which, among the other fields, has the “commentary_post_id” field related to the “post_id” field of the “post” table.

I want to create a collection that only searches for comments related to each post that is being displayed in the list. Searching the “comment” table, filtering the comments so that the “comment_post_id” field is the same as the “post_id” field of the current line of the post list.

Any suggestions on the best approach to do this?

1 Like

Hello, I think you’re looking for JOINs - they work with foreign key relationships like yours, and they basically get the matching records, in your case comments and embed them into your collection’s items (posts) where you can then access them.

Check out this article I wrote, I think it might give you an idea about how to pull this off. It’s definitely doable though. If you will still feel stuck, I also do 1:1 sessions where I help people with these kinds of things.

Then if you want to filter the data more in depth, e.g based on the JOINed data, you also can do that, we did this for a few partners, it’s also described in the article, in the Filtering section.