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

collection cache key generates invalid SQL for relations with joins #30315

Closed
dpogue opened this issue Aug 18, 2017 · 0 comments
Closed

collection cache key generates invalid SQL for relations with joins #30315

dpogue opened this issue Aug 18, 2017 · 0 comments

Comments

@dpogue
Copy link

dpogue commented Aug 18, 2017

Steps to reproduce

Test case: https://gist.github.com/dpogue/f168bc6bc24848396bf6694623532b3a

Expected behavior

Rails should generate a cache key

Actual behavior

Rails generates a select statement that does not join the right tables, but still includes them in the where clause. This results in an invalid SQL statement that causes a database exception.

Workarounds

If you call #load on the relation before trying to generate a cache key, it is able to calculate the key on the data in memory, which avoids making any SQL statements.
Of course, that means now all your data has been loaded into memory, which is probably what you were trying to avoid by using caching.

System configuration

Rails version: 5.1.3 (test case is against master)

Ruby version: 2.3.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants