Tanuj Doshi
08/05/2022, 12:09 PMNurul
08/05/2022, 1:35 PMTanuj Doshi
08/06/2022, 4:36 AMconst users = await this.prisma.user.findMany({
where: {
OR: [
{
completed_profile: true,
deleted: false,
},
{
completed_profile: true,
deleted: true,
},
],
},
});
and i have take reference of soft delete middleware for users model
now, this thing also didn't work
i am getting only those records who have deleted as false valueMichael Jay
08/06/2022, 2:43 PMwhere: {
completed_profile: true,
deleted: true
}
Discussion
If you remember in the other person's use case, they wanted to get back ALL records (soft-deleted AND not deleted). And the point that I was trying to make was that you can OR with deleted: false & deleted: true, but that's the same thing as not putting the deleted clause in there at all. In your case, your where clause is exactly equivalent to:
where: { completed_profile: true }
It seems like your use case is about getting "all data with deleted flag true". This means that your where clause should NOT include the deleted: false. And thus:
where: {
completed_profile: true,
deleted: true
}
In other words, I interpret your use case as "get all users who have completed their profile and whose accounts are deleted."
Now let's talk about your other issue. You say that you are getting only those records who have deleted: false. This is unexpected behavior. Your query SHOULD return those records, but it should also return the records that have deleted: true.
The first thing that I would check is whether your table does indeed have any deleted users to return to you. You can easily check out your table with Prisma Studio.
If you DON'T have any deleted users who have completed their profile, then naturally your query would have returned only those that aren't deleted.
So with the query you've written, if you aren't getting any deleted records back, here's what I think the most likely reasons are, in order.
1. You don't actually have any records that meet the qualifying clause: "has completed profile and is deleted". Check your DB to find out if this is the case.
2. Your query returned both records that have deleted: false AND records that have deleted: true, but they were clumped in a way that it looked like you were only getting deleted: false records back. To check this, you could run a filter on the returned array: users.filter(user => user.deleted)
. This would be the same thing as just writing the new query clause as I specified above.
Another thing to check, which could maybe indicate a bug in your BE logic, is to run a query with the where clause ONLY checking on deleted: true. You could potentially be changing the completed_profile value to false when you set deleted to true, for example. Which would mean you had no records that matched completed_profile: true AND deleted: true.