I am attempting to use the acts_as_paranoid gem with no luck. I have a Client model:
class Client < ActiveRecord::Base
acts_as_paranoid
has_many :purchases, dependent: :destroy
has_many :payments, dependent: :destroy
end
and when I destroy a client with purchases and / or payments, and then attempt to recover, only the client is recovered, and not the associations.
> 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
If I delete the client:
> c.destroy
and run Client.only_deleted, I see the client that was just deleted. However, when I recover it and attempt to load the purchases or payments, there are none.
> Client.only_deleted.first.recover
> c = Client.find(231) # success
> c.payments.length # fail
=> 0
The associated records are not recovered. Am I missing something?
I didn't realize I needed to run:
for all the associated models and add:
to the model's as well. After adding that, everything runs as expected