How to aggregate by subject


#1

I have the following datamodel.prisma and I’d like to count of each subject by a student. For example student with id of 1234 has mathematics 2, science 3 etc.

type Student {
  id: ID! @unique
  email: String! @unique
  firstName: String!
  lastName: String!
  advisor: Teacher! @relation(name:"StuentToTeacher")
  assignments: [Assignment!] @relation(name:"AssignmentToStudent", onDelete: CASCADE)
  parentEmail1: String!
  parentEmail2: String
  updatedAt: DateTime!
  createdAt: DateTime!
}

type Teacher {
  id: ID! @unique
  email: String! @unique
  firstName: String!
  lastName: String!
  assignments: [Assignment!] @relation(name:"AssignmentToTeacher")
  advisees: [Student!] @relation(name:"StuentToTeacher")  
  subjects: [Subject!]!
  updatedAt: DateTime!
  createdAt: DateTime!
}

type Staff {
  id: ID! @unique
  email: String! @unique
  firstName: String!
  lastName: String!
  role: String!
  updatedAt: DateTime!
  createdAt: DateTime!
}

type Assignment {
  id: ID! @unique
  student: Student! @relation(name:"AssignmentToStudent", onDelete: SET_NULL)
  name: String!
  subject: Subject!
  teacher: Teacher! @relation(name:"AssignmentToTeacher")
  summative: Boolean!
  date: DateTime!
  dateCompleted: DateTime
  detentionDate: DateTime
  detentionAttendance: DateTime
  updatedAt: DateTime!
  createdAt: DateTime! 
}

type Subject {
  id: ID! @unique
  name: String!
  updatedAt: DateTime!
  createdAt: DateTime!
}

type Studentsubject {
  id: ID! @unique 
  user: Student!
  subjects: [Subject!]!
}

I am not sure how to achieve this.


#2

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.