Hey, if I have a table called 'profiles' like so: ...
# sql
e
Hey, if I have a table called 'profiles' like so:
Copy code
create table if not exists public.profiles (
  id uuid references auth.users primary key,
  project text
);
When doing a query via the supabase JS client, how do you join on some of the data from the auth.users table?
s
I think in such a case, rather you create a public.
users
table with the columns you will need from the auth.
users
table and setup a trigger to always populate the users table that is in the public schema instead. I'm not sure but I don't think you can query via the js client from the auth schema
o
You can get the user metadata from the JS client
e
Ok thanks - what part does the
references auth.users
play then? I understand it created a FK, does it just enforce the id matches up with one in the auth.users table?
s
from there, you could do something like
Copy code
from('profiles')select('id, users(<the primary or foreign key>, some_other_field
)')
I'm not sure what you mean by 'enforce' but I agree with the first part
e
By enforce I mean, if I created a row in
profiles
with an ID which does not exist within
auth.users
, would this error?
o
Yes
s
I think in this case, POSTGRES rules of primary/foreign keys would apply. I've never tried it
@User try it with a valid guid, but that is not in your db
o
Good catch, but it fails too
e
Ah awesome, that makes sense now