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

Joins Argument Behavior Differs from Where and GORM V1 #4133

Closed
cameron-dunn-silo opened this issue Mar 3, 2021 · 1 comment · Fixed by go-gorm/prometheus#28
Closed

Joins Argument Behavior Differs from Where and GORM V1 #4133

cameron-dunn-silo opened this issue Mar 3, 2021 · 1 comment · Fixed by go-gorm/prometheus#28
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@cameron-dunn-silo
Copy link

GORM Playground Link

go-gorm/playground#291

Description

I expect the args given to Joins to behave similarly to the args given to Where. In the Playground shown above the behavior for Slice arguments appears to differ. The behavior also differs from GORM V1 (not shown in playground but I have verified this locally).

Expected behavior:
query.Joins("JOIN X ON X.id = y.x_id AND x.some_column IN (?)", []uint{1, 2}) would generate a fragment like x.some_column IN (1, 2).

This is observed in GORM V1, and in similar Where usage (within respect to the some_column IN (?)).

Problematic behavior:
query.Joins("JOIN X ON X.id = y.x_id AND x.some_attribute IN (?)", []uint{1, 2}) generates x.some_column IN ((1, 2)). This will likely result in an error within the DB from an unexpected type.

This can be worked around by simply writing the statement as query.Joins(JOIN X ON X.id = y.x_id AND x.some_attribute IN ?, []uint{1, 2}) (omitting parenthesis around ?).

Perhaps in Where and GORM V1 parentheses wrapping the ? are detected and none are added unless necessary?

@cameron-dunn-silo
Copy link
Author

Thank you -- very much appreciate the quick fix and the new release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
2 participants