为什么 Grails 中不鼓励删除数据?
请注意,Grails 不提供 deleteAll 方法,因为不鼓励删除数据,并且通常可以通过布尔标志/逻辑来避免删除数据。
为什么不鼓励删除数据?
Note that Grails does not supply a deleteAll method as deleting data is discouraged and can often be avoided through boolean flags/logic.
Why is deleting data discouraged?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为他们实际上是在说删除数据不好,但他们没有提供删除表中所有数据的便捷方法,因为你可能会
在你打算键入时
意外调用以及这样做的后果这可能相当可怕。如果您确实想删除所有实例,则很简单:
这是您不太可能意外调用的内容
I don't think they're actually saying that deleting data is bad, but they don't provide a convenience method for deleting all data in a table, because it's possible that you might accidentally call
when you meant to type
and the consequences of that could be fairly dire. If you really want to delete all instances, it's as simple as:
which is something you're unlikely to invoke accidentally
和唐一样,我同意他们并没有说这完全是坏事。
我阅读文档引用的方式是,在许多应用程序中,将记录标记为“隐藏”或“过期”而不是删除它,然后从显示/查询/等中删除它更合适。因此。这主要适用于需要历史数据保存或审计的应用程序。
该建议绝对是根据具体情况而定的,并且取决于您的应用程序的要求。
Like Don, I agree that they're not saying it's completely bad.
The way I read that documentation quote is that, in many applications, it's more appropriate to flag a record as "hidden" or "expired" instead of deleting it, and then remove it from displays/queries/etc. accordingly. This is mostly for applications that require historical data preservation or auditing.
The advice is definitely situational, and depends on the requirements of your application.