-
-
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
fix polymorphic joins with rails > 5.2 #1004
fix polymorphic joins with rails > 5.2 #1004
Conversation
I was able to confirm that this solves my issue. Thanks again. |
one polymorphism test is fixed. There are still several failures. Basically, any test that does an outer join is still doing an inner join.
one polymorphism test is fixed. There are still several failures. Basically, any test that does an outer join is still doing an inner join.
one polymorphism test is fixed. There are still several failures. Basically, any test that does an outer join is still doing an inner join.
@gregmolnar, I just ran this against baby_squeel's test suite (branch here, results here). It seems like this does fix #902 and #955, so great work. It fixed all of the tests that were specifically related to polymorphism. Those tests had been broken in baby_squeel since Active Record 5.2 initially came out. However, #955 seems to be in play still. You'll notice that some of the tests that should say The branch also includes this change as a workaround for the fact that |
@rzane Thanks for the info. I need to find a few hours block when I go over again this and find the root cause. |
Thanks, guys for the work on this! I would really appreciate it if you can merge this one @gregmolnar . |
@kieranklaassen the trouble is the fix on this branch causes issues if you use |
@gregmolnar I appreciate your efforts very much!! If you do not have time but could share your idea for the fix I might be able to help out here too. Thanks! |
@gregmolnar I'd love to help out here too. We ourselves depend on baby_squeel, and it'd be awesome if I can be of assistance in speeding up this process a bit. If it's easier / less time consuming for you to do a brain-dump here, I'm more than happy to try and give it a go! |
I need to get into the code to get my head around the problem again to be able to make a brain-dump and I will probably just fix it if I manage to get there. |
24687d0
to
99cbc19
Compare
I finally managed to work on this and I think it is fixed now, although I couldn't come up with specs so far. |
@rzane Actually, those alias errors looks like caused by ransack too, and there is a PR to fix that: https://github.com/activerecord-hackery/ransack/pull/1005/files |
Thanks again for digging into this @gregmolnar. It seems like once a relation starts to do any outer join, all subsequent joins become outer joins? Take this example: Post.joining { author.outer.comments } In the example above, I would expect
Another issue is the alias detection. Here's a gist of what that looks like in Baby Squeel. def find_alias(associations)
join_association = find_join_association(associations)
join_association.table
end Baby Squeel is successfully finding the correct JoinAssociation. On previous versions of Active Record, |
I merged this, since it fixes most of the issues and I want to make master work with Rails 6. I will open a follow up issue for the remaining issue. |
* Find the table * Use polyamorous from master * With activerecord-hackery/ransack#1004, all but one polymorphism test is fixed. There are still several failures. Basically, any test that does an outer join is still doing an inner join. * Explain how this is completely broken * Add byebug for development/testing * Have Active Record build tables for their aliases This may help with rzane#97. * Fix test for equivalent logic The new version of Active Record or Polyamorous seems to switch the order of these two SQL conditions, but the new statement is logically equivalent to the old one. * Use `variants` for SQL snapshot change * Make it possible to get good polymorphic joins Actually getting polymorphic joins to work correctly will require either explicitly specifying the master branch of the `ransack` project (commit c9cc20de9e0f or something with equivalent functionality) in the project `Gemfile` or the `ransack` project releasing a new 2.x (> 2.3.2) version with that functionality. Addresses most of the Active Record 5.2.x (>= 5.2.1) problems in rzane#97. The only remaining issues are around inner joins after left joins. * Track all associations used to find correct alias By tracking the associations accumulated within an expression, we can best even Active Record's own `#where` method's ability to correctly set conditions on column values via associations. * Reimplement #find_join_association iteratively Replacing recursive method calls with plain iteration is almost certainly more performant. * Revert unnecessary changes from commit 90e02e2 * Lock down the supported versions of ActiveRecord * Update rspec, rake, and sqlite3 * Run against Ruby 2.6 * Drop support for Active Record versions that have reached EOL * Remove old variants * Remove broken image from the readme * Install latest bundler * Explicit require test dependencies * Remove filewatcher * Run on GitHub actions * Require coveralls * Run as a matrix * Share the environment variables * Use the coveralls action * Not sure what is going on here... * Run against 5.2.0 and 5.2.5 * Give each job a name * Remove coverage * Mark failing tests as pending * Get 5.2.0 passing again * Remove coverage * Bump * Merge `join_dependency` back into this project, because my dreams did not really come true * Fix checking for version as string * Add changes from 1.4.0.beta1 to CHANGELOG.md * Build pull requests * remove old code from activerecord < 5.2 * removed BabySqueel::Pluck * reduce complexety after merging `join_dependency` back into this project * Fix table alias when joining a polymorphic table twice (rzane#108) * Update changelog for v1.4.0 * Bump version to v1.4.0 * Tidy up version comparison code * Bump version to v1.4.1 * add support for activerecord 6.0 * add support for activerecord 6.1 * speed up BabySqueel::ActiveRecord::VersionHelper * add support for activerecord 7.0 * update .github/workflows/build.yml to test rails 7.0 and ruby 3.0 / 3.1 * Apply version-specific monkey-patches outside of the method definition * Update changelog for v1.4.2 * v1.4.2 * ISSUE-117: left_joins performs INNER JOIN with ActiveRecord 6.1.4.4 * Update changelog for 1.4.3 release * Bump to v1.4.3 * ISSUE-119: Nested merge-joins query causes NoMethodError with ActiveRecord 6.1.4.4 rzane#119 * Prepare v1.4.4 * ISSUE-121: Drop support for ActiveRecord older than 6.0 * AR 6.1: fix - FrozenError: can't modify frozen object: [] * Bump v2.0.0 Co-authored-by: Ray Zane <[email protected]> Co-authored-by: Richard Weeks <[email protected]> Co-authored-by: Jonas S <[email protected]>
closes #996 and #902 and #955
I still need to add some specs to cover this.