-
-
Notifications
You must be signed in to change notification settings - Fork 807
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
Fixes polymorphic joins. #1122
Fixes polymorphic joins. #1122
Conversation
387a71f
to
8d418b4
Compare
* Polymorphic joins have been missing a critical join constraint that is responsible for only returning polymorphic records of the specified type. * Override ActiveRecord::Reflection::AbstractReflection#join_scope to add this constraint if the reflection is polymorphic.
8d418b4
to
01d35ef
Compare
Thank you @PhilCoggins |
I've just upgraded to Rails 6.1 (master branch), and am having an error come up with polymorphic joins using Ransack. Any ideas @PhilCoggins ? Been doing some digging but can't find a solution yet. Here's a framework trace that I get:
And error is: It seems as though join_constraints only takes two args, but there are three being passed to it from ActiveRecord. |
Hi @Jacoblab1 , I have not started using Rails 6.1 yet, and it looks like this project isn't building against it either. I think for a start you'll want to add an override in That would honestly just be a start. I would frankly caution against using this library altogether beyond Rails 6.0, Ransack modifies a ton of ActiveRecord private API that has changed a lot, Ransack just hasn't been able to keep up with it all. Our organization is slowly replacing Ransack with an internal implementation (ideally we will OSS, but no definite timeframe on that). |
Thanks for getting back to me! I played around with patching the override, but it ended opening up some other problems that were getting pretty complicated. As I'm only really using Ransack for filters on one controller, I think I'll just go ahead and re-build the filters myself with scopes. I figure that will be easier to maintain for me. |
@PhilCoggins @Jacoblab1 So is the rails 6.1 about "polyamorous/activerecord_6.1_ruby_2/join_dependency" was resolved ? I just follow up but didn't get it. Perhaps you can help to clarify. Or what solution to use/Thanks |
OK Got it, just upgrade ransack and that errors are gone.
|
Polymorphic joins have been missing a critical join constraint that
is responsible for only returning polymorphic records of the specified
type.
Override ActiveRecord::Reflection::AbstractReflection#join_scope to
add this constraint if the reflection is polymorphic.
Polymorphic searching has been broken in Ransack since rails/rails@49bcb00.
This PR closes #1039, closes #1120, and closes #1077.
This bug has been a source of great frustration for our organization, and presumably many users of this library are completely unaware of the incorrect queries being formed by this library. I have no idea how long these Polymorphic hacks on ActiveRecord will last, but hopefully this will be caught in the future with the test addition in this PR.