George Lewis
12/22/2021, 11:00 AMmodel 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
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?Maciek K
12/22/2021, 11:42 AMprofile nested in user in the query. That doesn't seem to be the same like schema. Anyway can you try like this:
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
})