From 70465fd6f2a2e09cac9ecf12269628c130599bfc Mon Sep 17 00:00:00 2001 From: SystemGlitch Date: Tue, 2 Aug 2022 09:53:27 +0200 Subject: [PATCH] Raw join duplication prevention handle 'AS' keyword --- filter_test.go | 2 +- join.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/filter_test.go b/filter_test.go index 02e8872..2448d31 100644 --- a/filter_test.go +++ b/filter_test.go @@ -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{ diff --git a/join.go b/join.go index bdc447c..3228dc4 100644 --- a/join.go +++ b/join.go @@ -13,7 +13,7 @@ import ( ) var ( - joinRegex = regexp.MustCompile("(?i)((LEFT|RIGHT|FULL)\\s+)?((OUTER|INNER)\\s+)?JOIN\\s+[\"'`]?(?P\\w+)[\"'`]?\\s+([\"'`]?(?P\\w+)[\"'`]?)?\\s*ON") + joinRegex = regexp.MustCompile("(?i)((LEFT|RIGHT|FULL)\\s+)?((OUTER|INNER)\\s+)?JOIN\\s+[\"'`]?(?P\\w+)[\"'`]?\\s+((AS\\s+)?[\"'`]?(?P\\w+)[\"'`]?)?\\s*ON") ) // Join structured representation of a join query.