acts_as_paranoid
acts_as_paranoid copied to clipboard
ActiveRecord queries with :includes do not respect :with_deleted => true
I can't see a way around the N+1 problem without using :includes in my Active Record queries. Per the documentation:
class ParanoiacParent < ActiveRecord::Base
has_many :children, :class_name => "ParanoiacChild"
end
class ParanoiacChild < ActiveRecord::Base
belongs_to :parent, :class_name => "ParanoiacParent"
belongs_to :parent_with_deleted, :class_name => "ParanoiacParent", :with_deleted => true
end
However if the following is called in a controller:
@paranoiac_children = ParanoiacChild.includes(:parent_with_deleted).all
The log load statement shows a "('paranoiac_parents'.'deleted_at' IS NULL)" in the WHERE clause resulting in undefined method
errors. I guess I'm forced to avoid using :includes. Is this behavior by design?
It doesn't work for me also. I don't get undefined method error but it just ignores the "with_deleted" option. I used a temporary dirty hack to get it working:
@projects = current_user.projects.includes(:users,:stages).where("users.deleted_at IS NOT NULL or users.deleted_at IS NULL")
having the same problem. would be awesome if this was fixed - cheers!
Even I have the same problem not sure how to go about it
+1
+1
+1
Just hit this today. +1
+1
+1
:+1: