Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

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

Open
moottoast opened this issue Apr 26, 2012 · 10 comments
Open

Comments

@moottoast
Copy link

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?

@vahtel
Copy link

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")

@paulkoegel
Copy link

having the same problem. would be awesome if this was fixed - cheers!

@perumal
Copy link

perumal commented Nov 6, 2012

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

@pelargir
Copy link

+1

2 similar comments
@chrismhilton
Copy link

+1

@tkupari
Copy link

tkupari commented May 31, 2013

+1

@timscott
Copy link
Contributor

Just hit this today. +1

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

See also goncalossilva/acts_as_paranoid#62.
Better we remove acts_as_paranoid and filter manually?
@AknEp
Copy link

AknEp commented Jun 30, 2014

+1

@nfriend21
Copy link

+1

1 similar comment
@mamantoha
Copy link

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.