0

This question might have a super easy answer, but as I am new to PostgreSQL/PostgREST, I am not sure how to achieve it.

What I want to create is a schema/REST endpoint which allows me to query for posts posted by followed users.

Currently, the schema looks like this:

USERS

- first_name
, last_name
, id

POSTS

- id
, text
, author_id --foreign key to a user

CONNECTIONS

- id
, follower --foreign key to a user
, followed --foreign key to a user

I want to be able to query for the posts posted by users which given user follows, but I am not sure how to achieve this using postgREST.

JNevill
  • 46,980
  • 4
  • 38
  • 63

1 Answers1

0

posts posted by users which given user follows,

Try it like:

GET /posts?select=*,users!inner(connections!inner!followed(*))&users.connections.follower=eq.<your_user_id>

With that you'll get the posts you want though with some extra data.

Steve Chavez
  • 931
  • 10
  • 13
  • 1
    You sir are a saint. I got it working by first fetching the list of followed ids and then fetching articles with follower=in.(), but I knew that it was not and ideal solution. This is awesome, thank you! – Dominik Grodl Mar 21 '22 at 15:11