From 47150353e61c1d208b88355a120294319da8ad9a Mon Sep 17 00:00:00 2001 From: jinjiaji Date: Tue, 9 Jul 2019 16:37:36 +0800 Subject: [PATCH] fix: #2549 Check the DeleteAt field of the join table --- join_table_handler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/join_table_handler.go b/join_table_handler.go index a036d46d..6fbd20c0 100644 --- a/join_table_handler.go +++ b/join_table_handler.go @@ -175,6 +175,12 @@ func (s JoinTableHandler) JoinWith(handler JoinTableHandlerInterface, db *DB, so joinConditions = append(joinConditions, fmt.Sprintf("%v.%v = %v.%v", quotedTableName, scope.Quote(foreignKey.DBName), destinationTableName, scope.Quote(foreignKey.AssociationDBName))) } + deletedAtField, hasDeletedAtField := scope.FieldByName("DeletedAt") + if !scope.Search.Unscoped && hasDeletedAtField { + sql := fmt.Sprintf("%v.%v IS NULL", quotedTableName, scope.Quote(deletedAtField.DBName)) + joinConditions = append(joinConditions, sql) + } + var foreignDBNames []string var foreignFieldNames []string