Rails 3的覆盖摧毁无取消回调,并触发一个ROLLBACK [英] Rails 3 Override Destroy without Canceling callbacks, and triggering a ROLLBACK

查看:290
本文介绍了Rails 3的覆盖摧毁无取消回调,并触发一个ROLLBACK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的期望的行为是当破坏被称为上的一个实例,该实例实际上不会被破坏,但它只是被标记为已销毁。这需要渗透了任何模型关联。

My desired behavior is that when destroy is called on an instance, that instance will not actually be destroyed, but it will just be marked as having been destroyed. This needs to percolate up for any model associations.

在我不希望真正摧毁,但只是为删除我有一个停用字段标在车型。

In the models that I don't want to actually destroy, but just mark them as deleted I have a deactivated field.

这是我可以告诉的<这样做的V3.0.0方法是覆盖 destroy_without_callbacks (这是ActsAsParanoid做它的方式),但这种方法不再3.0.0存在,再加上我不兴奋有关覆盖私有方法。

From what I can tell the < v3.0.0 way of doing this was to override destroy_without_callbacks (That's the way ActsAsParanoid does it), however that method no longer exists in 3.0.0, plus I'm not excited about overriding private methods.

我也试过实现回调,但每文档所作的任何改变呼叫后背交易的一部分,并因此回滚以及

I also tried implementing callbacks, but per the docs any changes made in the call backs are part of the transaction, and are thus rolled-back as well.

我的回调是这样的:

  after_destroy :mark_deactivated

  def mark_deactivated
    if self.respond_to?(:deactivated) then
      self.deactivated = DateTime.now
      self.save
      false
    else
      true
    end
  end

我怎样才能prevent我的记录实际销毁不停止回调,并有我的回滚的变化?

How can I prevent the actual destruction of my record without stopping callback, and having my changes rolled-back?

推荐答案

看看这个宝石:的https:// github上.COM /线框/ delete_paranoid

这篇关于Rails 3的覆盖摧毁无取消回调,并触发一个ROLLBACK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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