letourpowerscombine
11/25/2021, 4:14 PMusers_pages
many-to-many table. The users in this table are stored by user_id
foreign key.
I'm trying to display all of the email addresses
, for every user that belongs to a given page
. So I need to find all of the `user_id`s for a requested page — and then pull the email addresses
associated with each of those `user_id`s. Something like this:
javascript
const { data, error } = await supabase
.from('users_pages')
.select(`*, users(email)`)
.eq('page_id', PAGE_ID)
What query should go into .select()
, in order to return the email addresses
from users
table?Steve
11/25/2021, 6:21 PMjs
const { data, error } = await supabase
.from('pages')
.select(`*, users(email)`)
.eq('id', PAGE_ID)
Then you'd have a response like:
json
[
{"id": 1, "users": [
{"email": "a@user.com"}
]}
]
letourpowerscombine
11/25/2021, 7:47 PM{message: "Could not find a relationship between pages and users in the schema cache",…}
hint: "If a new foreign key between these entities was created in the database, try reloading the schema cache."
I've attached an image of how my public`users_pages` table is setup. The only other tables in the DB are the standard auth.users
table, and the public pages
(which is indexed by id
, as in your example.)
Does it looked set-up correctly? Any other thoughts?letourpowerscombine
11/25/2021, 7:48 PMletourpowerscombine
11/26/2021, 8:25 AMauth.users
table instead of a public.users
table. When I created the public.users
table and ran the same set-up, this worked!
javascript
const { data, error } = await supabase
.from('pages')
.select(`*, users(email)`)
.eq('id', this_page.id)