#Prisma - Query Relation / Relationship between two tables

9 messages · Page 1 of 1 (latest)

glad jewel
#

Prisma - Query Relation / Relationship between two tables

livid cove
#

Hi vmathi Can you try with the include keyword please?

try {
 const switchData = await db.switch.findUnique({
   where: {
     id: switchId, // replace switchId with the actual switch id
   },
   include: {
     images: true,
   },
 });

 if (!switchData) {
   return <Custom404 />;
 }

 console.log(switchData.images); // this will log the images belonging to the switch
} catch (error) {
 console.log(error);
}

glad jewel
#

there are multiple images, videos, and prices for each switch

#

wait I think i've done my schema wrong

#

I have

#

thank you!