如何实现软删除

zor*_*119 2 grails grails-orm grails-domain-class

任何人都可以告诉我什么是实现软删除的好方法?我可以deleted在班上找到一个属性,但我的问题是如何轻松忽略deleted = true我的搜索,列表等中的实例.

所以,而不是说Domain.findByDeleted(true)只是Domain.list()忽略已删除的实例,而不是说Domain.findByPropertyAndDeleted('property', true)只是说Domain.findByProperty('property').

有这么好的方法吗?

doe*_*eri 7

我建议使用命名查询.就像是

static namedQueries = {
    notDeleted {
        ne 'deleted', true
    }
}
Run Code Online (Sandbox Code Playgroud)

你可以使用像Domain.notDeleted.list()Domain.notDeleted.findByProperty(value)