testas
testas
PPrisma
Created by testas on 6/6/2024 in #help-and-questions
Help Needed with Nested CreateMany!
I'm concerned that returning tons of records can be very costly/inefficient. I don't see an option to select specific properties to return using createManyAndReturn, but maybe i'm missing it? is there a way to for example select to return only IDs?
10 replies
PPrisma
Created by testas on 6/6/2024 in #help-and-questions
Help Needed with Nested CreateMany!
Thanks for the suggestion. The cavieat with your approach is, createMany doesn't return the records. B\ut I re-read the docs and found this https://www.prisma.io/docs/orm/prisma-client/queries/crud#create-records-and-connect-or-create-related-records It seems like a more efficient way to go about it! It seems like a new thing, as it's only available at 5.14
10 replies
PPrisma
Created by testas on 6/6/2024 in #help-and-questions
Help Needed with Nested CreateMany!
Here’s the minimal version of my Prisma schema:
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Classroom {
id String @id @default(cuid())
teacherId String
students ClassroomMembership[]
assignmentSets AssignmentSet[]
teacher User @relation(fields: [teacherId], references: [id], onDelete: Cascade)
}

model ClassroomMembership {
id String @id @default(cuid())
classroomId String
userId String
classroom Classroom @relation(fields: [classroomId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model Assignment {
id String @id @default(cuid())
classroomId String
studentId String
assignmentSetId String
portfolios Portfolio[]
classroom Classroom @relation(fields: [classroomId], references: [id], onDelete: Cascade)
student User @relation(fields: [studentId], references: [id], onDelete: Cascade)
assignmentSet AssignmentSet @relation(fields: [assignmentSetId], references: [id], onDelete: Cascade)
}

model AssignmentSet {
id String @id @default(cuid())
classroomId String
classroom Classroom @relation(fields: [classroomId], references: [id], onDelete: Cascade)
assignments Assignment[]
}

model Portfolio {
id String @id @default(cuid())
assignmentId String
studentId String
assignment Assignment @relation(fields: [assignmentId], references: [id], onDelete: Cascade)
student User @relation(fields: [studentId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
assignments Assignment[]
portfolios Portfolio[]
classroomMembership ClassroomMembership[]
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Classroom {
id String @id @default(cuid())
teacherId String
students ClassroomMembership[]
assignmentSets AssignmentSet[]
teacher User @relation(fields: [teacherId], references: [id], onDelete: Cascade)
}

model ClassroomMembership {
id String @id @default(cuid())
classroomId String
userId String
classroom Classroom @relation(fields: [classroomId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model Assignment {
id String @id @default(cuid())
classroomId String
studentId String
assignmentSetId String
portfolios Portfolio[]
classroom Classroom @relation(fields: [classroomId], references: [id], onDelete: Cascade)
student User @relation(fields: [studentId], references: [id], onDelete: Cascade)
assignmentSet AssignmentSet @relation(fields: [assignmentSetId], references: [id], onDelete: Cascade)
}

model AssignmentSet {
id String @id @default(cuid())
classroomId String
classroom Classroom @relation(fields: [classroomId], references: [id], onDelete: Cascade)
assignments Assignment[]
}

model Portfolio {
id String @id @default(cuid())
assignmentId String
studentId String
assignment Assignment @relation(fields: [assignmentId], references: [id], onDelete: Cascade)
student User @relation(fields: [studentId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
assignments Assignment[]
portfolios Portfolio[]
classroomMembership ClassroomMembership[]
}
I had to separate it due to too much text limitation.
10 replies