Implementing many-to-many relationships with the UI #710
-
I must be missing something, but I'm currently experimenting with supabase, and I can't seem to figure out how to create many-to-many or one-to-many relationships using the UI. Are there any blog posts, that discuss this? I am more than sure that I'm missing something. I've read through the docs pretty much cover -to-cover and can't seem to find anything other than this: https://supabase.io/docs/guides/database#relationships Any help/suggestions/guidance would be greatly appreciated! Thanks in advance for the help! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 28 replies
-
Hey @gaurangrshah, a many-to-many relationship is created by essentially creating 2 tables, then a final "join" table to connect these together. manytomany.mov |
Beta Was this translation helpful? Give feedback.
-
Worked like a charm, thanks...I could swear I tried this, but I def. must've done something wrong in the process. Either way thanks a ton! |
Beta Was this translation helpful? Give feedback.
-
@kiwicopple sorry, but what If I want to insert to many-to-many relation using supabase api? currently, I'm able to do that effortlessly with prisma api. code sample using Prisma const publish = await prisma.job.create({
data: {
title,
uri,
body,
published,
lead,
Profile: { connect: { id: userId } },
expired: false,
company: { connect: { id: company } },
contract: { connect: { id: contract } },
experience: { connect: { id: experience } },
location: { connect: { id: location } },
categories: { connect: categories },
created_at: new Date(),
updated_at: new Date(),
},
}); using supabase api const user: any = supabase.auth.user();
const newJobDetails: any = {
title: dataJob.title,
uri: dataJob.body,
lead: dataJob.lead,
body: dataJob.body,
contract: dataJob.contractId,
experience: dataJob.experienceId,
location: dataJob.location,
company: dataJob.companyId,
published: dataJob.published,
userId: user?.id,
categories: [{"id":2}, {"id":4}],
created_at: new Date(),
updated_at: new Date(),
};
const { data, error } = await supabase
.from("job")
.insert([newJobDetails]); |
Beta Was this translation helpful? Give feedback.
Hey @gaurangrshah, a many-to-many relationship is created by essentially creating 2 tables, then a final "join" table to connect these together.
manytomany.mov