I have two models with a belongs_to - has_many relationship which you can see below (I included only the parts of the code relevant to this question since the models are quite big):
product.rb
 class Product < ActiveRecord::Base
   attr_accessible :title, :description, [...]
   has_many :test_cycles
   acts_as_paranoid
 end
test_cycle.rb
 class TestCycle < ActiveRecord::Base
   belongs_to :product, with_deleted: true
   acts_as_paranoid
   delegate :title, to: :product, prefix: true
 end
According the the Readme on Github (https://github.com/goncalossilva/acts_as_paranoid), this should work:
class Parent < ActiveRecord::Base
    has_many :children, :class_name => "ParanoiacChild"
end
class ParanoiacChild < ActiveRecord::Base
    belongs_to :parent
  belongs_to :parent_including_deleted, :class_name => "Parent", :with_deleted => true
  # You cannot name association *_with_deleted
end
parent = Parent.first
child = parent.children.create
parent.destroy
child.parent #=> nil
child.parent_including_deleted #=> Parent (it works!)
However, if I delete the parent product of a test cycle and try to get access it via test_cycle.product (assuming both a test_cycle and a product object exist), it returns nil (even though with_deleted: true is included in the model!).
If I call test_cycle.product_title on the same test_cycle with the deleted product, it runs the query "SELECT products.* FROM products WHERE products.id = 1 LIMIT 1" and I get a runtime error:
"RuntimeError: TestCycle#product_title delegated to product.title, but product is nil".
If I, however, run the query directly in the database, the product is found (since it is not really deleted but only has a deleted_at field set by acts_as_paranoid).
So it seems that the 'with_deleted: true' in the product model is ignored. Any idea why this is happening? Or could there be any other reason why this doesn't work?
I hope I'm making myself clear, if not, please ask and I will happily provide more information. Thanks!
                        
You have to also provide foreign_key. If you look at the specs it is obvious, but the documentation is not up to date.
Use this code:
Here is the snippet from the specs (see: https://github.com/goncalossilva/acts_as_paranoid/blob/rails3.2/test/test_helper.rb):