Joins on accounts from public schema
jide opened this issue · comments
When using created_by and updated_by columns, the relation points to auth.users table.
I would have liked to be able to retrieve the name of the account through this relation, but it is not possible to query relations across different schemas.
The same issue arises with account_id columns in public schema tables.
What approach do you recommand for this ?
you should be able to join across schemas, maybe I'm not understanding.
select
a.name,
p.title
from posts
join basejump.accounts a on a.id = posts.account_id
The permissions are setup so that as long as the user is a member of the account, they should have access to that account and the above should work. Am I misunderstanding?
Ah, yes I meant using supabase js client. So I guess the answer is to make a function and call it via rpc ?
Got it - makes sense.
You could do it through a function, but that might get annoying depending on how many ways you need to slice it up. If just a specific use case, I probably would
If you're starting to add multiple fields to account metadata and it's feeling a bit more like an "account profile" of sorts - I'd recommend doing what Supabase recommends for users. Create an account_profile (or whatever) table in public schema and then create a trigger that auto-populates it on create for the account. Here's a link to their guide: https://supabase.com/docs/guides/auth/managing-user-data#creating-user-tables
Ok thanks ! Actually that's what I was doing until migrating to basejump. I have some data that I need to be tied to accounts, and I hesitate to leverage metadata or create an ad hoc table. I'll think about it.