We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have the following relationship between the tables categories and sub-categories:
categories
sub-categories
Also the database.types.ts created by the supabase gen types:
database.types.ts
supabase gen types
categories: { Row: { color: string | null created_at: string id: number name: string | null user_id: string } Insert: { color?: string | null created_at?: string id?: number name?: string | null user_id?: string } Update: { color?: string | null created_at?: string id?: number name?: string | null user_id?: string } Relationships: [] } "sub-categories": { Row: { category_id: number color: string | null created_at: string id: number name: string | null } Insert: { category_id: number color?: string | null created_at?: string id?: number name?: string | null } Update: { category_id?: number color?: string | null created_at?: string id?: number name?: string | null } Relationships: [ { foreignKeyName: "sub-categories_category_id_fkey" columns: ["category_id"] isOneToOne: false referencedRelation: "categories" referencedColumns: ["id"] }, ] }
Select the sub-categories and its corresponding category using the relationship category_id and categories:id and also get the types definition as described in the doc: https://supabase.com/docs/guides/database/joins-and-nesting?queryGroups=language&language=js#typescript-types-for-joins
category_id
categories:id
const subcategoriesDataQuery = supabase.from('sub-categories').select(` id, name, color, categories( id, name, color ) `)
The inferred type brings an array of categories instead of a single object:
But the query result brings the categories as an object not an array:
Trying to find a solution for it I found this discussion where one of the suggestions are to use the foreign key in the query: https://github.com/orgs/supabase/discussions/7610#discussioncomment-8513745
Then if I change the query to:
const subcategoriesDataQuery = supabase.from('sub-categories').select(` id, name, color, category:categories!sub-categories_category_id_fkey( id, name, color ) `)
I get this error related to the type:
But the query keeps working:
The inferred types working according to the query structure.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug report
Describe the bug
Context:
I have the following relationship between the tables
categories
andsub-categories
:Also the
database.types.ts
created by thesupabase gen types
:Goal:
Select the sub-categories and its corresponding category using the relationship
category_id
andcategories:id
and also get the types definition as described in the doc: https://supabase.com/docs/guides/database/joins-and-nesting?queryGroups=language&language=js#typescript-types-for-joinsProblems:
The inferred type brings an array of categories instead of a single object:
But the query result brings the categories as an object not an array:
Trying to find a solution for it I found this discussion where one of the suggestions are to use the foreign key in the query: https://github.com/orgs/supabase/discussions/7610#discussioncomment-8513745
Then if I change the query to:
I get this error related to the type:
But the query keeps working:
Expected behavior
The inferred types working according to the query structure.
The text was updated successfully, but these errors were encountered: