rare-sapphire
rare-sapphire13mo ago

select multiple joins

how do you do multiple joins with select on useTable when using supabase?
8 Replies
kapa.ai
kapa.ai13mo ago
Hi @fuddlesworth. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In refine, you can handle multiple joins using the meta property in the useTable hook when using Supabase. The meta property is used to pass additional information that can be read by data provider methods. For example, if you have a many-to-many relationship like movies <-> categories_movies <-> categories, you can get the categories data of a user using the meta property as shown below:
const { tableProps, sorter } = useTable<IUser>({
resource: "movies",
meta: {
select: "*, categories!inner(name)",
},
});
const { tableProps, sorter } = useTable<IUser>({
resource: "movies",
meta: {
select: "*, categories!inner(name)",
},
});
In this example, the select value in the meta object is used to perform the relational database operation. The select property is used internally by the Supabase data provider methods. You can find more details in the Supabase data provider documentation (https://refine.dev/docs/packages/documentation/data-providers/supabase). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@205390473609609217> kapa.ai is still learning and improving, please let us how it did by reacting below
rare-sapphire
rare-sapphire13mo ago
@kapa.ai how would i join categories to another table in that example
kapa.ai
kapa.ai13mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To join categories to another table, you would use the select property in the meta object of the useTable hook. The select property is used to perform relational database operations in the Supabase data provider. Here's an example of how you might join categories to a posts table:
const { tableProps, sorter } = useTable<IPost>({
resource: "posts",
meta: {
select: "*, categories(name)",
},
});
const { tableProps, sorter } = useTable<IPost>({
resource: "posts",
meta: {
select: "*, categories(name)",
},
});
In this example, the select property is set to "*, categories(name)", which means it will select all fields from the posts table and the name field from the categories table. The categories table is joined to the posts table through the categories field in the posts table. You can find more details in the Supabase data provider documentation (https://refine.dev/docs/packages/documentation/data-providers/supabase). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@205390473609609217> kapa.ai is still learning and improving, please let us how it did by reacting below
rare-sapphire
rare-sapphire13mo ago
@kapa.ai no, how would i join categories to movies and another table to categories
kapa.ai
kapa.ai13mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To join categories to movies and another table (let's say tags) to categories, you would use the select property in the meta object of the useTable hook. The select property is used to perform relational database operations in the Supabase data provider. Here's an example of how you might join these tables:
const { tableProps, sorter } = useTable<IMovie>({
resource: "movies",
meta: {
select: "*, categories(name, tags(name))",
},
});
const { tableProps, sorter } = useTable<IMovie>({
resource: "movies",
meta: {
select: "*, categories(name, tags(name))",
},
});
In this example, the select property is set to "*, categories(name, tags(name))", which means it will select all fields from the movies table, the name field from the categories table, and the name field from the tags table. The categories table is joined to the movies table through the categories field in the movies table, and the tags table is joined to the categories table through the tags field in the categories table. You can find more details in the Supabase data provider documentation (https://refine.dev/docs/packages/documentation/data-providers/supabase). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@205390473609609217> kapa.ai is still learning and improving, please let us how it did by reacting below