filter(...).delete()?
YannisMarios opened this issue · 3 comments
YannisMarios commented
Hi, I have a question
I have defined a static method like this:
accessTokens.defineStatic('removeExpired', async function() {
let expired = await this.filter(token => token('expires_on').lt(new Date()));
if(expired.length) {
expired.forEach(token => async () => {
await this.delete(token.id)
})
}
});
expired is an array of objects and I would like to delete them without having to loop over them by doing something like:
await this.filter(token => token('expires_on').lt(new Date())).delete()
is this possible? I tried this above and I get error:
ThinkyError: Value for [id] must be defined.
in ReQL it is possible to do:
r.db("auth_db").table("accessTokens").filter(token => token('expires_on').lt(new Date())).delete()
cur3n4 commented
Does await this.filter(token => token('expires_on').lt(new Date())).delete().execute()
do the trick?
YannisMarios commented
@cur3n4 It works!!! Thank you!!
I can't believe I missed this!
cur3n4 commented
@YannisMarios My pleasure