問題描述
問題
在處理產品和訂單的 Web 應用程序中,我想維護前雇員(用戶)與他們處理的訂單之間的信息和關系.我想維護過時產品和包含這些產品的訂單之間的信息和關系.
In a web application dealing with products and orders, I want to maintain information and relationships between former employees (users) and the orders they handled. I want to maintain information and relationships between obsolete products and orders which include these products.
但是我希望員工能夠清理管理界面,例如刪除前員工、過時的產品、過時的產品組等.
However I want employees to be able to de-clutter the administration interfaces, such as removing former employees, obsolete products, obsolete product groups etc.
我正在考慮實施軟刪除.那么,人們通常如何做到這一點?
I'm thinking of implementing soft-deletion. So, how does one usually do this?
我的即時想法
我的第一個想法是在每個應該軟刪除的對象表中粘貼一個flag_softdeleted
TINYINT NOT NULL DEFAULT 0"列.或者可以改用時間戳?
My first thought is to stick a "flag_softdeleted
TINYINT NOT NULL DEFAULT 0" column in every table of objects that should be soft deletable. Or maybe use a timestamp instead?
然后,我在每個相關的 GUI 中提供一個顯示已刪除"或取消刪除"按鈕.單擊此按鈕,您將在結果中包含軟刪除的記錄.每個刪除的記錄都有一個恢復"按鈕.這有意義嗎?
Then, I provide a "Show deleted" or "Undelete" button in each relevant GUI. Clicking this button you will include soft-deleted records in the result. Each deleted record has a "Restore" button. Does this make sense?
你的想法?
此外,如果您提供任何相關資源的鏈接,我將不勝感激.
Also, I'd appreciate any links to relevant resources.
推薦答案
我就是這樣做的.我有一個 is_deleted
字段,默認為 0.然后查詢只需檢查 WHERE is_deleted = 0
.
That's how I do it. I have a is_deleted
field which defaults to 0. Then queries just check WHERE is_deleted = 0
.
我盡量遠離任何硬刪除.有時它們是必要的,但我將其設為僅限管理員的功能.這樣我們可以硬刪除,但用戶不能...
I try to stay away from any hard-deletes as much as possible. They are necessary sometimes, but I make that an admin-only feature. That way we can hard-delete, but users can't...
實際上,您可以使用它在您的應用程序中使用多個層"軟刪除.所以每個都可以是一個代碼:
In fact, you could use this to have multiple "layers" of soft-deletion in your app. So each could be a code:
0
-> 未刪除1
-> 軟刪除,顯示在管理用戶的已刪除項目列表中2
-> 軟刪除,除管理員用戶外不顯示任何用戶3
-> 僅對開發者顯示.
0
-> Not Deleted1
-> Soft Deleted, shows up in lists of deleted items for management users2
-> Soft Deleted, does not show up for any user except admin users3
-> Only shows up for developers.
擁有其他 2 個級別仍然允許經理和管理員在刪除列表太長時清理它們.而且由于前端代碼只檢查 is_deleted = 0
,它對前端是透明的...
Having the other 2 levels will still allow managers and admins to clean up the deleted lists if they get too long. And since the front-end code just checks for is_deleted = 0
, it's transparent to the frontend...
這篇關于軟刪除最佳實踐(PHP/MySQL)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!