Andy
Andy

Reputation: 640

How do I access fields in Supabase foreign-key table?

I've got a fairly simple database set up in Supabase. There are two tables: transactions and payees. The transactions table has columns for id, created_at, date, amount, and payee. The payees table has columns for id, created_at, and name. The transactions.payee field is set up as a relationship to the payees.id field.

I can query the sample data I've loaded and get a list of transactions for a given payee by doing this:

select * from transactions where payee = 2

However, this displays the payee id (i.e. "2") instead of the payee name, which is what I'd like to see. Some googling turned up a fairly complicated-looking "join" statement; I was able to duplicate it and get the desired result, but A) it seems overly complex given what I assume is a fairly common use-case for relational data, and 2) I have no idea how I would extrapolate it to include other foreign table data (i.e. what if I wanted to add a job and a bank account later).

What is the correct way to access fields in the foreign table?

Upvotes: 0

Views: 111

Answers (0)

Related Questions