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

Debug exists subquery #757

Closed
wants to merge 2 commits into from
Closed

Debug exists subquery #757

wants to merge 2 commits into from

Conversation

coorasse
Copy link
Member

@coorasse coorasse commented Nov 12, 2021

This PR is a draft to debug the behavior of an exists subquery implemented in #691

Run the relevant test with:

DB='sqlite' bundle exec appraisal activerecord_6.0.0 rspec spec/cancan/model_adapters/accessible_by_has_many_through_spec.rb[1:3:2:1]

My debugging started because I wanted to understand why we need this JOIN: https://github.com/CanCanCommunity/cancancan/pull/691/files#diff-1ac9b926205ddc47154cac149a2a53d61c308efc15b59bfdea7b13ec6565fff1R63-R64

Apparently is because otherwise it is basically impossible to alias the tables in the inner exists subquery.

@coorasse coorasse self-assigned this Nov 12, 2021
@@ -89,7 +89,8 @@ class Editor < ActiveRecord::Base
if CanCan::ModelAdapters::ActiveRecordAdapter.version_greater_or_equal?('5.0.0')
describe 'selecting custom columns' do
it 'extracts custom columns correctly' do
posts = Post.accessible_by(ability).where(published: true).select('title as mytitle')
posts = Post.where(title: 'a').accessible_by(ability).where(published: true).select('title as mytitle')
puts posts.to_sql
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check output to see the issue

@coorasse coorasse closed this Mar 23, 2022
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

Successfully merging this pull request may close these issues.

1 participant