Add QueryFields mode when query many2many relations

This commit is contained in:
Jinzhu 2020-12-25 16:35:25 +08:00
parent 59730417aa
commit ad8a5c0d1a
2 changed files with 3 additions and 3 deletions

View File

@ -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.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}, Table: clause.Table{Name: association.Relationship.JoinTable.Table},
ON: clause.Where{Exprs: queryConds}, ON: clause.Where{Exprs: queryConds},
}}}) }}})

View File

@ -8,10 +8,10 @@ require (
github.com/lib/pq v1.6.0 github.com/lib/pq v1.6.0
github.com/stretchr/testify v1.5.1 github.com/stretchr/testify v1.5.1
gorm.io/driver/mysql v1.0.3 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/sqlite v1.1.4
gorm.io/driver/sqlserver v1.0.5 gorm.io/driver/sqlserver v1.0.5
gorm.io/gorm v1.20.7 gorm.io/gorm v1.20.8
) )
replace gorm.io/gorm => ../ replace gorm.io/gorm => ../