-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typegen is not respecting unique table constraint #612
Comments
I agree this is a non-intuitive query pattern of PostgREST. As a workaround, you can specify the foreign key to get back a single entity. For eg. const { data } = supabase.
from("customers").
select("*, orders!orders_customer_id_fkey (id), addresses!addresses_customer_id_fkey (id)").
single() Hope it helps. |
Thank you for the quick reply @sweatybridge 🙏 . So that didn't work for me unfortunately. Maybe I should clarify – the actual data returned from the query has the correct structure (not an array), only the types are wrongly inferred as an array of objects. Maybe you understood that already, but regardless specifying the foreign key doesn't get me the right type structure unfortunately :( |
Thank you for clarifying. I'm transferring this issue to postgres-meta repo which the cli uses for typegen. @soedirgo might have a better idea of what fixes are needed here. |
Describe the bug
I have three tables. One main table
customers
and two linked tablesaddresses
andorders
. They both are linked to thecustomers
table'sid
column, but theaddresses
table has a unique constraint oncustomer_id
relation column. The problem is that the generated types assumes that both table relations are one to many.To Reproduce
Steps to reproduce the behavior:
npx supabase gen types typescript --local > types/supabase.ts
const supabase = createClient<Database>()
and queryconst { data } = supabase .from("customers") .select("*, orders (id), addresses (id)").single()
data.orders
anddata.addresses
are both an array of objects.Expected behavior
The types to respect the unique constraint and be an object and not an array of objects.
Desktop
The text was updated successfully, but these errors were encountered: