PHP Doctrine SoftDelete - 包括已删除的记录?
如果我有一个 PHP Doctrine 对象充当 SoftDelete,是否可以在某些查询的结果中包含已删除的项目?我正在寻找的是这样的东西......
$q = Doctrine_Query::create()
->select('*')
->from('Test t')
->where('id < ?', 25)
*->includeDeleted()*;
这样的东西对于大多数查询很有用,我希望排除已删除的记录,但有时(例如,对于管理员)我希望能够包含软记录已删除。有没有一些好的方法可以使用 SoftDelete 来做到这一点,或者我应该简单地在大多数查询中添加一个额外的 where 子句?
If I have one of my PHP Doctrine objects act as a SoftDelete, is it possible to include deleted items in the results of certain queries? What I'm looking for is something like this...
$q = Doctrine_Query::create()
->select('*')
->from('Test t')
->where('id < ?', 25)
*->includeDeleted()*;
Something like this would be useful as for most queries I want deleted records excluded, but sometimes (for example, to administrators) I want to be able to include records that have been soft deleted. Is there some good way to do this with SoftDelete or should I simply add an additional where clause onto most queries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它返回表中的所有记录(包括 softDeleted)
It returns all records from table (include softDeleted)
看起来您可以禁用软删除过滤器
http://atlantic18.github.io/DoctrineExtensions/doc/softdeleteable.html
// 这将禁用 SoftDeleteable 过滤器,因此“软删除”的实体将出现在结果中
$em->getFilters()->disable('软删除');
Looks like you may disable soft-deleteable filter
http://atlantic18.github.io/DoctrineExtensions/doc/softdeleteable.html
// This will disable the SoftDeleteable filter, so entities which were "soft-deleted" will appear in results
$em->getFilters()->disable('soft-deleteable');
粗略浏览一下此处 和此处 ,此功能似乎不是由 SoftDelete 行为提供的。您必须按照您的建议手动添加
where
子句。(我可能是错的,但我很确定
Doctrine_Query
不能通过像Doctrine_Record
那样的行为来动态扩展。您可以 总是编写一个特殊的Doctrine_Query
子类来添加includeDeleted()
,但这似乎比它的价值更值得:))From a cursory glance at the source here and here, this functionality does not seem to provided by the
SoftDelete
behaviour. You have to add awhere
clause manually like you suggest.(I may be wrong, but I'm pretty sure
Doctrine_Query
can not be extended dynamically by way of a behaviour like you can withDoctrine_Record
. You could always write a specialDoctrine_Query
subclass which addsincludeDeleted()
, but that seems like more thouble than it's worth :) )此后您可以选择、更新、删除数据,如软删除关闭。
After this you can select, update, delete data like softDelete is off.
我们在 Doctrine 1.2.2 中遇到了一个错误,其中 ATTR_USE_DQL_CALLBACKS 被忽略,并且 softdelete 列的名称错误。解决方案是使用
虚拟类覆盖侦听器:
We had a bug in Doctrine 1.2.2 where ATTR_USE_DQL_CALLBACKS was ignored AND the softdelete column had the wrong name. The solution is to overwrite the listener:
with a dummy class: