From ad8a5c0d1ace1b9608fdaaae920fe17ebb5cf32a Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 25 Dec 2020 16:35:25 +0800 Subject: [PATCH] Add QueryFields mode when query many2many relations --- association.go | 2 +- tests/go.mod | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/association.go b/association.go index 7adb8c91..d93ff8ca 100644 --- a/association.go +++ b/association.go @@ -470,7 +470,7 @@ func (association *Association) buildCondition() *DB { tx.Clauses(clause.Expr{SQL: strings.Replace(joinStmt.SQL.String(), "WHERE ", "", 1), Vars: joinStmt.Vars}) } - tx.Clauses(clause.From{Joins: []clause.Join{{ + tx = tx.Session(&Session{QueryFields: true}).Clauses(clause.From{Joins: []clause.Join{{ Table: clause.Table{Name: association.Relationship.JoinTable.Table}, ON: clause.Where{Exprs: queryConds}, }}}) diff --git a/tests/go.mod b/tests/go.mod index 03283a53..f6912a0f 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -8,10 +8,10 @@ require ( github.com/lib/pq v1.6.0 github.com/stretchr/testify v1.5.1 gorm.io/driver/mysql v1.0.3 - gorm.io/driver/postgres v1.0.5 + gorm.io/driver/postgres v1.0.6 gorm.io/driver/sqlite v1.1.4 gorm.io/driver/sqlserver v1.0.5 - gorm.io/gorm v1.20.7 + gorm.io/gorm v1.20.8 ) replace gorm.io/gorm => ../