我正在尝试使用acts_as_paranoid gem,但没有运气。我有一个Client
模型:
class Client < ActiveRecord::Base
acts_as_paranoid
has_many :purchases, dependent: :destroy
has_many :payments, dependent: :destroy
end
当我通过购买和/或付款销毁客户,然后尝试恢复时,只有客户被恢复,而不是关联。
> c = Client.find(231)
> c.payments.length
Payment Load (0.6ms) SELECT "payments".* FROM "payments" WHERE "payments"."client_id" = $1 [["client_id", 231]]
=> 1
> c.purchases.length
Purchase Load (0.6ms) SELECT "purchases".* FROM "purchases" WHERE "purchases"."client_id" = $1 [["client_id", 231]]
=> 1
如果我删除客户端:
> c.destroy
然后运行Client.only_deleted
,我看到刚刚删除的客户端。但是,当我恢复它并尝试加载购买或付款时,没有。
> Client.only_deleted.first.recover
> c = Client.find(231) # success
> c.payments.length # fail
=> 0
关联的记录不会被恢复。我错过了什么吗?