P
Prisma•7mo ago
kunwar.eth

How to filter if a variable is not in database

Hi, I am fetching users like:
const users = await prisma.users.findMany({
where: {
accountStatus: status as accountStatus,
},
select: {
id: true,
email: true,
name: true,
phoneNumber: true,
didCreated: true,
category: true,
accountStatus: true,
did: true,
createdAt: true,
updatedAt: true,
},
});
const users = await prisma.users.findMany({
where: {
accountStatus: status as accountStatus,
},
select: {
id: true,
email: true,
name: true,
phoneNumber: true,
didCreated: true,
category: true,
accountStatus: true,
did: true,
createdAt: true,
updatedAt: true,
},
});
Now if i dont have a category feild in db in on of user i am getting error:
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
Instead what i want is to leave that category for that user and send remaining data
5 Replies
Nurul
Nurul•7mo ago
Hey 👋 Is categories defined as a required field in your schema.prisma file?
kunwar.eth
kunwar.ethOP•7mo ago
I dont think so:
No description
kunwar.eth
kunwar.ethOP•7mo ago
I opened db and deleted category by myself for one user... Now when i load users it gives error:
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
Nurul
Nurul•7mo ago
In your schema, category is defined as a required field as it doesn't have a (?) Could you change it to
category String?
category String?
and after that invoke npx prisma generate` and then try to invoke the same query?
kunwar.eth
kunwar.ethOP•7mo ago
Thanks for the info
Want results from more Discord servers?
Add your server