Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Expected at most 1 item for 'courseContent', got 5 #563

Closed
AhmedElywa opened this issue Mar 12, 2020 · 1 comment
Closed

Expected at most 1 item for 'courseContent', got 5 #563

AhmedElywa opened this issue Mar 12, 2020 · 1 comment

Comments

@AhmedElywa
Copy link

AhmedElywa commented Mar 12, 2020

Simple schema

model LessonTaking {
  id                Int                @default(autoincrement()) @id
  courseTaking      CourseTaking?
  assignmentTakings AssignmentTaking[]
}

model CourseTaking {
  id            Int            @default(autoincrement()) @id
  courseContent CourseContent
  lessonTakings LessonTaking[]
}

model CourseContent {
  courseCode    String?
  id            Int            @default(autoincrement()) @id
  title         String         @default("")
  courseTakings CourseTaking[]
}

model AssignmentTaking {
  id                Int                @default(autoincrement()) @id
  startedAt         DateTime?
  submittedAt       DateTime?
  timeTaken         Int?
  totalPoints       Float?
  assignmentContent AssignmentContent?
  lessonTaking      LessonTaking?
}

model AssignmentContent {
  id                Int                @default(autoincrement()) @id
  isAssessment      Boolean            @default(false)
  order             Int?
  title             String?
  totalPoints       Int?
  courseContent     CourseContent?
  assignmentTakings AssignmentTaking[]
}

prisma client query get this error Expected at most 1 item for 'courseContent', got 5

await prisma.lessonTaking.findMany({
          select: {
            id: true,
            courseTaking: {
              select: {
                id: true,
                courseContent: {
                  select: {
                    id: true
                  }
                }
              }
            },
            assignmentTakings: {
              select: {
                id: true
              }
            }
          }
        })

if this help this query log

[SERVER] prisma:query SELECT 1
[SERVER] prisma:query SELECT "local"."LessonTaking"."id", "local"."LessonTaking"."courseTaking" FROM "local"."LessonTaking" WHERE ("local"."LessonTaking"."id") IN (SELECT "t0"."id" FROM "local"."LessonTaking" AS "t0" INNER JOIN "local"."CourseTaking" AS "j0" ON ("j0"."id") = ("t0"."courseTaking") WHERE "j0"."id" = $1) OFFSET $2
[SERVER] prisma:query SELECT "local"."CourseTaking"."id", "local"."CourseTaking"."courseContent" FROM "local"."CourseTaking" WHERE "local"."CourseTaking"."id" IN ($1) OFFSET $2
[SERVER] prisma:query SELECT "local"."CourseContent"."id" FROM "local"."CourseContent" WHERE "local"."CourseContent"."id" IN ($1) OFFSET $2

using this prisma query not have same issue and get same data with anther way

await prisma.courseTaking.findMany({
         select: {
           id: true,
           courseContent: {
             select: {
               id: true,
             }
           },
           lessonTakings: {
             select: {
               id: true,
               assignmentTakings: {
                 select: {
                   id: true
                 }
               }
             }
           }
         }
       })

using version 2.0.0-preview024

it's same issue here #399 but this was one level nested but here is two level nested

@malekjaroslav
Copy link

Related: prisma/prisma#1785

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants