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

Compile error for optional association preloads #922

Closed
akadusei opened this issue Jan 17, 2023 · 4 comments · Fixed by #925
Closed

Compile error for optional association preloads #922

akadusei opened this issue Jan 17, 2023 · 4 comments · Fixed by #925

Comments

@akadusei
Copy link
Contributor

I'm getting a compile error when preloading optional associations. It seems to originate from here:

assoc = preload_query.id(record.{{ foreign_key }}).first?

Error: 

The 'eq' method can't compare a column to a value that may be 'nil'.
# ...

It seems the #eq method does not accept nilable arguments.

@jwoertink
Copy link
Member

This is correct, the eq method doesn't allow for nilable arguments. You'd have to use nilable_eq in that case... but I guess the bigger question is why are you getting this error? Or... why has this not come up until now? 😂 I have a few nilable associations in my apps that get preloaded, so it would seem that either this code should work, or it should have thrown this error quite a while ago. Very strange 🤔

@matthewmcgarvey
Copy link
Member

This bug was introduced in 285a902 which is really new and I think only affects preloading in the new way (with an existing record).

@akadusei
Copy link
Contributor Author

You'd have to use nilable_eq in that case... but I guess the bigger question is why are you getting this error?

I got this error while testing Shield with the master branch of Avram. It's an existing code, calling BearerLoginQuery.preload_oauth_client which compiles OK with Avram v1.0.0-rc1.

This bug was introduced in 285a902 which is really new and I think only affects preloading in the new way (with an existing record).

That's correct. The said line should probably check if the association is nil and call the appropriate method.

@jwoertink
Copy link
Member

Ah! That explains it. Yeah, I haven't tested the main branch stuff 😅 Good find.

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 a pull request may close this issue.

3 participants