开发者

Why is deleting data discouraged in Grails?

From http://grails.org/doc/1.3开发者_StackOverflow中文版.x/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.3.2%20Deleting%20Objects:

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?


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

book.deleteAll()

when you meant to type

book.delete()

and the consequences of that could be fairly dire. If you really want to delete all instances, it's as simple as:

Book.executeUpdate("delete Book") 

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜