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)
The hibernate filter plugin can automatically add the predicate deleted = false to every query that is performed for a particular domain class. However, my testing indicated that this plugin does not work with Grails 2.0.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With