<small id='btmC9'></small><noframes id='btmC9'>

      <tfoot id='btmC9'></tfoot>
      <legend id='btmC9'><style id='btmC9'><dir id='btmC9'><q id='btmC9'></q></dir></style></legend>

      <i id='btmC9'><tr id='btmC9'><dt id='btmC9'><q id='btmC9'><span id='btmC9'><b id='btmC9'><form id='btmC9'><ins id='btmC9'></ins><ul id='btmC9'></ul><sub id='btmC9'></sub></form><legend id='btmC9'></legend><bdo id='btmC9'><pre id='btmC9'><center id='btmC9'></center></pre></bdo></b><th id='btmC9'></th></span></q></dt></tr></i><div id='btmC9'><tfoot id='btmC9'></tfoot><dl id='btmC9'><fieldset id='btmC9'></fieldset></dl></div>
        <bdo id='btmC9'></bdo><ul id='btmC9'></ul>
    1. 软删除最佳实践(PHP/MySQL)

      时间:2023-10-04
      <legend id='JVDH1'><style id='JVDH1'><dir id='JVDH1'><q id='JVDH1'></q></dir></style></legend>
        <tbody id='JVDH1'></tbody>

            <bdo id='JVDH1'></bdo><ul id='JVDH1'></ul>
              <tfoot id='JVDH1'></tfoot>

              <small id='JVDH1'></small><noframes id='JVDH1'>

                <i id='JVDH1'><tr id='JVDH1'><dt id='JVDH1'><q id='JVDH1'><span id='JVDH1'><b id='JVDH1'><form id='JVDH1'><ins id='JVDH1'></ins><ul id='JVDH1'></ul><sub id='JVDH1'></sub></form><legend id='JVDH1'></legend><bdo id='JVDH1'><pre id='JVDH1'><center id='JVDH1'></center></pre></bdo></b><th id='JVDH1'></th></span></q></dt></tr></i><div id='JVDH1'><tfoot id='JVDH1'></tfoot><dl id='JVDH1'><fieldset id='JVDH1'></fieldset></dl></div>
              • 本文介绍了软删除最佳实践(PHP/MySQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                问题

                在处理产品和订单的 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 Deleted
                • 1 -> Soft Deleted, shows up in lists of deleted items for management users
                • 2 -> Soft Deleted, does not show up for any user except admin users
                • 3 -> 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模板网!

                上一篇:PHP、MySQL、PDO - 从 UPDATE 查询中获取结果? 下一篇:创建一个线程私人消息系统,如 facebook 和 gmail

                相关文章

                最新文章

                  • <bdo id='hoVEf'></bdo><ul id='hoVEf'></ul>

                  <tfoot id='hoVEf'></tfoot>

                  <i id='hoVEf'><tr id='hoVEf'><dt id='hoVEf'><q id='hoVEf'><span id='hoVEf'><b id='hoVEf'><form id='hoVEf'><ins id='hoVEf'></ins><ul id='hoVEf'></ul><sub id='hoVEf'></sub></form><legend id='hoVEf'></legend><bdo id='hoVEf'><pre id='hoVEf'><center id='hoVEf'></center></pre></bdo></b><th id='hoVEf'></th></span></q></dt></tr></i><div id='hoVEf'><tfoot id='hoVEf'></tfoot><dl id='hoVEf'><fieldset id='hoVEf'></fieldset></dl></div>

                1. <legend id='hoVEf'><style id='hoVEf'><dir id='hoVEf'><q id='hoVEf'></q></dir></style></legend>

                  <small id='hoVEf'></small><noframes id='hoVEf'>