FindMany Where Confusion
I'm trying to do a simple "find many where" query on the following schema:
TLDR: a course has a 1 to many relationship with a scheduled event.
I have these two queries:
Query 1 returns and empty list.
Query 2 returns a list with many records.
Why is it that I don't get anything back from query 1???
TLDR: a course has a 1 to many relationship with a scheduled event.
model Course {
id Int @id @default(autoincrement())
subjectCode String
courseCode String
title String
shortTitle String
description String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ScheduledEvent ScheduledEvent[]
}
model ScheduledEvent {
id Int @id @default(autoincrement())
crn String @unique
description String
courseId Int
course Course @relation(fields: [courseId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ScheduledEventRegistrations ScheduledEventRegistrations[]
}model Course {
id Int @id @default(autoincrement())
subjectCode String
courseCode String
title String
shortTitle String
description String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ScheduledEvent ScheduledEvent[]
}
model ScheduledEvent {
id Int @id @default(autoincrement())
crn String @unique
description String
courseId Int
course Course @relation(fields: [courseId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ScheduledEventRegistrations ScheduledEventRegistrations[]
}I have these two queries:
Query 1 returns and empty list.
Query 2 returns a list with many records.
Why is it that I don't get anything back from query 1???
const events = await prisma.scheduledEvent.findMany({
where: {
course: {
title: {
contains: "Math",
},
},
},
include: {
course: true,
},
});
const courses = await prisma.course.findMany({
where: {
title: {
contains: "Math",
},
},
});const events = await prisma.scheduledEvent.findMany({
where: {
course: {
title: {
contains: "Math",
},
},
},
include: {
course: true,
},
});
const courses = await prisma.course.findMany({
where: {
title: {
contains: "Math",
},
},
});