Hey! I have a table called colleges & athletics. Both these have different data in the rows & columns, however the column id in colleges is always linked to some row in athletics with the same id. Now, I'm currently returning both of them like this, however this is really inefficient, is there anyway for me to return both with one call?
#Link a row in another table to a row and return both
11 messages · Page 1 of 1 (latest)
@clear field you should use the include clause after the where clause to include the data from the athletics table like so:
const aggregate = await prisma.colleges.findUniqueOrThrow({
where: {id},
include: { /* here comes the relation between the 2 tables*/ : true});
It won't let me use include
It's most likely because there is no relation between the two
First you have to make a relation between the 2 tables and then with Prisma, you need to migrate the changes to your database with migrate i suppose, the generate the Prisma Client and then try again(plus restart your TS server in VSCode)
You really don't have any relationset up based upon this image, you need to create it first then use PRisma to return your results
@tired hatch yeah, I ended up messing around with it and setting up the relation, pretty cool how it works however I did notice a bit slower response time when I first start the server and make a request to my API, it’s around 3 seconds, is it possible that there is something I can do to try fixing this? I use prisma accelerate so it does get faster when I repeat requests
Or is 3 seconds not that really much to worry about
Do appreciate you helping me out