Hi All, I am facing a problem and I spent more tha...
# orm-help
g
Hi All, I am facing a problem and I spent more than 5 hours trying to solve it with no luck. I have a model organizationMembership as follow
Copy code
model OrganizationMembership {
  id          String                   @id @default(cuid())
  permissions OrganizationPermission[]

  dailyVerseNotification Boolean? @default(false)

  organization   Organization @relation(fields: [organizationId], references: [id])
  organizationId String
  profile        Profile?     @relation(fields: [profileId], references: [id])
  profileId      String?
  user           User?        @relation(fields: [userId], references: [id])
  userId         String?

  startDate DateTime @default(now())
  updatedAt DateTime @updatedAt

  meetingRoomReservationModerated MeetingRoomReservation[]

  @@unique([userId, organizationId])
  // @@index([profileId])
  // @@index([userId])
  // @@index([organizationId])
  // @@unique([profileId, organizationId])
}
and a resolver to query all the organizationMemberships as follow
Copy code
async organizationMemberships(
    _parent: any,
    args: OrganizationMembershipsArgs,
    ctx: ContextInterface
  ): Promise<OrganizationMembership[]> {
    const organizationMemberships = ctx.prisma.organizationMembership.findMany({
      where: {
        id: args.where?.id,
        userId: args.where?.user?.id,
        organizationId: args.where?.organizationId?.length
          ? { in: args.where.organizationId }
          : undefined,
        user: {
          profile: {
            name_search_key: {
              contains: args.where?.name_search_key,
              mode: 'insensitive'
            }
          }
        }
      },
      skip: args.skip,
      take: args.first
    })
The problem is that when i run the query (Searching by OrganizationId) I only get the records that have a user entity not the rest (with null user). can anyone help?
m
Why is the
profile
nested in
user
in the query. That doesn't seem to be the same like schema. Anyway can you try like this:
Copy code
const organizationMemberships = ctx.prisma.organizationMembership.findMany({
      where: {
        id: args.where?.id,
        userId: args.where?.user?.id,
        organizationId: args.where?.organizationId?.length
          ? { in: args.where.organizationId }
          : undefined,
        OR :[
          { user: {
            profile: {
              name_search_key: {
                contains: args.where?.name_search_key,
                mode: 'insensitive'
              }
            }
          }},
          { user: { none: {}}}
        ]
      },
      skip: args.skip,
      take: args.first
    })