ActiveRecord queries with :includes do not respect :with_deleted => true #62

moottoast opened this Issue Apr 26, 2012 · 10 comments


None yet

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"

class ParanoiacChild < ActiveRecord::Base
    belongs_to :parent, :class_name => "ParanoiacParent"
    belongs_to :parent_with_deleted, :class_name => "ParanoiacParent", :with_deleted => true

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?

vahtel commented Jul 1, 2012

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!

perumal commented Nov 6, 2012

Even I have the same problem not sure how to go about it


tkupari commented May 31, 2013



timscott commented Nov 12, 2013

Just hit this today. +1

bennibu added a commit to foodcoops/foodsoft-archive that referenced this issue Jan 20, 2014

Removed article from includes in as it does not work with acts_as_par…

See also goncalossilva/acts_as_paranoid#62.
Better we remove acts_as_paranoid and filter manually?

AknEp commented Jun 30, 2014


@pelargir pelargir referenced this issue in ActsAsParanoid/acts_as_paranoid Feb 14, 2015


Feature: Remove condition for joins. #17



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment