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

Added example JOIN scope. #743

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

systemmonkey42
Copy link

@systemmonkey42 systemmonkey42 commented Jun 20, 2024

Explain your user case and expected results

Test case for issue go-gorm/gorm#7076

Gorm "Scopes" don't work as advertised when used as a join condition.

In this particular case, the following diff naively resolves the issue

diff --git chainable_api.go chainable_api.go
index e6c90cefe268..84c77c958634 100644
--- chainable_api.go
+++ chainable_api.go
@@ -257,6 +257,7 @@ func joins(db *DB, joinType clause.JoinType, query string, args ...interface{})
                Name: query, Conds: args, Selects: db.Statement.Selects,
                Omits: db.Statement.Omits, JoinType: joinType,
            }
+           db = db.executeScopes()
            if where, ok := db.Statement.Clauses["WHERE"].Expression.(clause.Where); ok {
                j.On = &where
            }

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