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

Multiple hash definitions results in invalid SQL #846

Open
afn opened this issue Apr 29, 2024 · 0 comments
Open

Multiple hash definitions results in invalid SQL #846

afn opened this issue Apr 29, 2024 · 0 comments

Comments

@afn
Copy link

afn commented Apr 29, 2024

Steps to reproduce

When there are multiple hash conditions, the generated SQL is invalid. See failing spec here: afn@bc1478d

The generated SQL is:

SELECT "legacy_mentions".* FROM "legacy_mentions" WHERE "legacy_mentions"."id" IN (SELECT "legacy_mentions"."id" FROM "legacy_mentions" LEFT OUTER JOIN "users" ON "users"."id" = "legacy_mentions"."user_id" LEFT OUTER JOIN "articles" ON "articles"."id" = "legacy_mentions"."article_id" LEFT OUTER JOIN "users" "users_articles" ON "users_articles"."id" = "articles"."user_id" WHERE (("users_articles"."company" = 1) OR ("users"."company_id" = 1)))

whereas it should be:

SELECT "legacy_mentions".* FROM "legacy_mentions" WHERE "legacy_mentions"."id" IN (SELECT "legacy_mentions"."id" FROM "legacy_mentions" LEFT OUTER JOIN "users" ON "users"."id" = "legacy_mentions"."user_id" LEFT OUTER JOIN "articles" ON "articles"."id" = "legacy_mentions"."article_id" LEFT OUTER JOIN "users" "users_articles" ON "users_articles"."id" = "articles"."user_id" WHERE (("users_articles"."company_id" = 1) OR ("users"."company_id" = 1)))

(Note company_id versus company.)

Expected behavior

Spec should pass

Actual behavior

Spec fails with an error

System configuration

Rails version: 6.1.0

Ruby version: 3.0.1

CanCanCan version 3.5.0 and current develop branch

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

1 participant