I have 2 tables as shown below where user table stores the users profile details and friends table which stores the friendship relation between 2 users where sent column links with user who has sent the request and recieved column links with user who gets the request notification to accept.
user {
id uuid
name string
}
friends {
id id
sent uuid (relation: user.id)
recieved uuid (relation: user.id)
accepted boolean
}
I want to query all the friends table where user's id is present either in sent or recieved field.
I can achieve this using
const { data, error } = await supabase
.from('friends')
.select('*')
.eq('accepted', true)
.or(`sent.eq.${user?.id},recieved.eq.${user?.id}`);
But the twist is i also want the joint tables of users (sent and request) along with it. Something like
const { data, error } = await supabase
.from('friends')
.select('*, recieved(*), sent(*)')
.eq('accepted', true)
.or(`sent.id.eq.${user?.id},recieved.id.eq.${user?.id}`);
But the following gives error since both fields come from 2 different foreign tables