Can anyone tell me what would be a good way to implement soft deletes? I can have a deleted
property in my class, but my question is how to easily ignore instances which have deleted = true
in my searches, listings and so on.
So, rather than saying Domain.findByDeleted(true)
just get Domain.list()
to ignore deleted instances, rather than saying Domain.findByPropertyAndDeleted('property', true)
just say Domain.findByProperty('property')
.
Is there a nice way of doing this?
I would recommend using a named query for this. Something like
static namedQueries = {
notDeleted {
ne 'deleted', true
}
}
which you could use like Domain.notDeleted.list()
or Domain.notDeleted.findByProperty(value)