Skip to content

Commit

Permalink
Raw join duplication prevention handle 'AS' keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Aug 2, 2022
1 parent a4fb56e commit 70465fd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion filter_test.go
Expand Up @@ -426,7 +426,7 @@ func TestFilterScopeWithAlreadyExistingRawJoin(t *testing.T) {

// We manually join a relation with a condition.
// We expect this join to not be removed nor duplicated, with the condition kept.
db = db.Joins(`LEFT JOIN filter_test_relations "Relation" ON id > ?`, 0)
db = db.Joins(`LEFT JOIN filter_test_relations AS "Relation" ON id > ?`, 0)

db = db.Model(&results).Scopes(filter.Scope(&Settings{}, schema)).Find(&results)
expected := map[string]clause.Clause{
Expand Down
2 changes: 1 addition & 1 deletion join.go
Expand Up @@ -13,7 +13,7 @@ import (
)

var (
joinRegex = regexp.MustCompile("(?i)((LEFT|RIGHT|FULL)\\s+)?((OUTER|INNER)\\s+)?JOIN\\s+[\"'`]?(?P<TableName>\\w+)[\"'`]?\\s+([\"'`]?(?P<Alias>\\w+)[\"'`]?)?\\s*ON")
joinRegex = regexp.MustCompile("(?i)((LEFT|RIGHT|FULL)\\s+)?((OUTER|INNER)\\s+)?JOIN\\s+[\"'`]?(?P<TableName>\\w+)[\"'`]?\\s+((AS\\s+)?[\"'`]?(?P<Alias>\\w+)[\"'`]?)?\\s*ON")
)

// Join structured representation of a join query.
Expand Down

0 comments on commit 70465fd

Please sign in to comment.