Hi all, what is the best way to run a `deleteMany`...
# orm-help
r
Hi all, what is the best way to run a
deleteMany
query where I have two where clauses, with one being an array of ids. For a basic example:
Copy code
model SurveyPermission {
  id           
  userId 
  surveyId 
}

const userIds = ['1', '2', '3'];
const surveyId = 'survey-id';

delete many from surveyPermissions where surveyId === surveyId && userId === one of userIds array
I thought I could use
has
but can't seem to get it working as I think that's just for enums. Obviously I could do this in a loop and use a single delete but ideally wanted to handle it in a single query .
r
Copy code
deleteMany({
  where: {
    surveyId: 'id',
    userId: { in: userIds }
  }
})
🙌 2
r
I was being so stupid! Thanks Ryan. Do you know if the whole query will fail if say an incorrect id is passed in?
e.g. 24 valid and 1incorrect
or will a count of 24 just be returned and the invalid one silently just fail
(just like a SQL in)
r
It will not fail, the values that match the user ids passed will be deleted
r
yeah just confirmed that cheers mat
mate
🙌 1
Is there a way to return those that failed in the query? Longshot...
not in I guess? ah nvm that wouldn't work
r
That wouldn't be possible unfortunately.
✅ 1