Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Remove condition for joins. #17

Closed
zekefast opened this issue Aug 29, 2014 · 7 comments
Closed

Feature: Remove condition for joins. #17

zekefast opened this issue Aug 29, 2014 · 7 comments

Comments

@zekefast
Copy link

It would be awesome if you would add ability to unscope joins or let unscoped affect joined associations as well.

Now there is no way to include deleted associations into joined conditions. It always adds something like "rabbits"."deleted_at" IS NULL to the FROM carrots INNER JOIN rabbits ON rabbits.id = carrots.rabbit_id.

@zzak
Copy link
Contributor

zzak commented Oct 6, 2014

@zekefast could you show me an example of how you think this should work? or how would you like to use it?

@kostyay
Copy link

kostyay commented Oct 22, 2014

I also need this feature.
Perhaps if there was a way to turn if all for a given query that would be awesome.

@pelargir
Copy link
Contributor

I'm having a similar problem, except with #includes instead of #joins. Here's an example:

class Schedule < ActiveRecord::Base
  belongs_to :resource, with_deleted: true
end

class Resource < ActiveRecord::Base
end

Schedule.all.includes(:resource)

Running the code above results in the following queries being executed:

SELECT `schedules`.* FROM `schedules`
SELECT `resources`.* FROM `resources` WHERE (`resources`.`deleted_at` IS NULL) AND `resources`.`id` IN (1103)

This returns incorrect results since deleted resources are being filtered out, despite the belongs_to association having specified with_deleted: true

This was a known issue in an older version of this gem:
goncalossilva/acts_as_paranoid#62

This was the pull request that fixed it:
goncalossilva/acts_as_paranoid#115

I'll submit a new pull request.

@zzak
Copy link
Contributor

zzak commented Feb 16, 2015

@pelargir I see, thank you!

@bradseefeld
Copy link

I am having the same problem as @pelargir with the :includes on a belongs_to which is configured for with_deleted: true. Any progress on merging the pull-request?

@zzak
Copy link
Contributor

zzak commented Oct 28, 2015

I'll see if we can get this cleaned up and merged before the final release <3

@zzak
Copy link
Contributor

zzak commented Jul 8, 2016

I've merged #37 so closing this ticket.

@zzak zzak closed this as completed Jul 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants