Symfony / Doctrine:“Soft update”如果一个字段已经改变了 [英] Symfony/Doctrine: "Soft update" if a certain field has changed

查看:137
本文介绍了Symfony / Doctrine:“Soft update”如果一个字段已经改变了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以在Doctrine中软删除(即不删除记录,而是添加一个已删除的值)。有一个扩展名。

I know you can soft delete in Doctrine (i.e. do not delete a record but rather add a "deleted" value). There's an extension for that.

现在我想知道有没有办法软更新一条记录。我的意思是没有实际更新记录,而是创建一个新记录,使旧的记录无效。在与soft-delete相同的扩展名中,有一个函数 loggable ,但是这个日志记录到另一个表。

Now I wonder if there's a way to "soft update" a record. I mean not actually update the record but rather create a new record and make the old one invalid. In the same extension as soft-delete, there's a function loggable, but this one logs to a different table.


  • 我可以创建一个控制器,而不是更新,软删除
    (从而无效)旧记录,然后创建一个新的
    新价值观。但我不确定这是否是一个很好的做法。

  • I could create a controller that, instead of updating, soft-deletes (and thus invalidates) the old record, and then creates a new one with the new values. But I'm unsure if this is a good practice.

也许我应该在对象本身上创建这个动作?但是我是
不确定如何做到这一点。

Maybe I should create this action on the object itself? But I'm unsure how to do this.

我已经研究了Versionable和EntityAudit(根据Tomas的建议),但是似乎这些捆绑做的太多了。我只是想检查一个给定的字段是否与旧的不同,如果没有:软删除旧的(我使用softDeleteable所以一个简单的 remove()会做)然后创建一个具有更改值的新值。

I've looked into Versionable and EntityAudit (as suggested by Tomas), but it seems these bundles do way too much. I merely want to check if a given field is different from the old one, and if not: soft-delete the old one (I'm using softDeleteable so a simple remove() will do); then create a new one with the changed values.

所以理想情况下,它会潜伏在阴影中,直到执行更新。然后从映射配置中读取需要监视的字段,如果这些字段与持久化的字段确实不同,程序应该执行 remove() persist()命令。

So ideally it would lurk in the shadows until an update is performed. Then read from the mapping configuration which fields it needs to watch, and if these fields are indeed different from what's persisted, the program should execute the remove() and persist() commands.

推荐答案

此扩展可能适合您的用例:

This extension might suit your use case:

  • simplethings/EntityAudit

它记录您要跟踪的任何更改。
所以应该很容易修改它,以满足您的需求。

It records any changes you want to track. So it should be pretty easy to modify it to meed your needs.

这篇关于Symfony / Doctrine:“Soft update”如果一个字段已经改变了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆