revert it to handle private joins
This commit is contained in:
parent
f9315d3d01
commit
a1d9d7dc18
@ -134,7 +134,7 @@ func Delete(config *Config) func(db *gorm.DB) {
|
||||
func(db *gorm.DB) {
|
||||
deleteClause.Modifier = db.Statement.Table
|
||||
},
|
||||
func(db *gorm.DB, tableAliasName string, join gorm.Join, relation *schema.Relationship) {
|
||||
func(db *gorm.DB, tableAliasName string, idx int, relation *schema.Relationship) {
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func HandleJoins(db *gorm.DB, prejoinCallback func(db *gorm.DB), perFieldNameCallback func(db *gorm.DB, tableAliasName string, join gorm.Join, relation *schema.Relationship)) {
|
||||
func HandleJoins(db *gorm.DB, prejoinCallback func(db *gorm.DB), perFieldNameCallback func(db *gorm.DB, tableAliasName string, idx int, relation *schema.Relationship)) {
|
||||
// inline joins
|
||||
fromClause := clause.From{}
|
||||
if v, ok := db.Statement.Clauses["FROM"].Expression.(clause.From); ok {
|
||||
@ -19,7 +19,7 @@ func HandleJoins(db *gorm.DB, prejoinCallback func(db *gorm.DB), perFieldNameCal
|
||||
prejoinCallback(db)
|
||||
|
||||
specifiedRelationsName := make(map[string]interface{})
|
||||
for _, join := range db.Statement.Joins {
|
||||
for idx, join := range db.Statement.Joins {
|
||||
if db.Statement.Schema != nil {
|
||||
var isRelations bool // is relations or raw sql
|
||||
var relations []*schema.Relationship
|
||||
@ -59,7 +59,7 @@ func HandleJoins(db *gorm.DB, prejoinCallback func(db *gorm.DB), perFieldNameCal
|
||||
tableAliasName = utils.NestedRelationName(parentTableName, tableAliasName)
|
||||
}
|
||||
|
||||
perFieldNameCallback(db, tableAliasName, join, relation)
|
||||
perFieldNameCallback(db, tableAliasName, idx, relation)
|
||||
|
||||
exprs := make([]clause.Expression, len(relation.References))
|
||||
for idx, ref := range relation.References {
|
||||
|
@ -104,10 +104,10 @@ func BuildQuerySQL(db *gorm.DB) {
|
||||
}
|
||||
}
|
||||
},
|
||||
func(db *gorm.DB, tableAliasName string, join gorm.Join, relation *schema.Relationship) {
|
||||
func(db *gorm.DB, tableAliasName string, idx int, relation *schema.Relationship) {
|
||||
columnStmt := gorm.Statement{
|
||||
Table: tableAliasName, DB: db, Schema: relation.FieldSchema,
|
||||
Selects: join.Selects, Omits: join.Omits,
|
||||
Selects: db.Statement.Joins[idx].Selects, Omits: db.Statement.Joins[idx].Omits,
|
||||
}
|
||||
|
||||
selectColumns, restricted := columnStmt.SelectAndOmitColumns(false, false)
|
||||
|
@ -260,7 +260,7 @@ func joins(db *DB, joinType clause.JoinType, query string, args ...interface{})
|
||||
|
||||
if len(args) == 1 {
|
||||
if db, ok := args[0].(*DB); ok {
|
||||
j := Join{
|
||||
j := join{
|
||||
Name: query, Conds: args, Selects: db.Statement.Selects,
|
||||
Omits: db.Statement.Omits, JoinType: joinType,
|
||||
}
|
||||
@ -272,7 +272,7 @@ func joins(db *DB, joinType clause.JoinType, query string, args ...interface{})
|
||||
}
|
||||
}
|
||||
|
||||
tx.Statement.Joins = append(tx.Statement.Joins, Join{Name: query, Conds: args, JoinType: joinType})
|
||||
tx.Statement.Joins = append(tx.Statement.Joins, join{Name: query, Conds: args, JoinType: joinType})
|
||||
return
|
||||
}
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -4,3 +4,5 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
|
||||
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
||||
|
@ -33,7 +33,7 @@ type Statement struct {
|
||||
Selects []string // selected columns
|
||||
Omits []string // omit columns
|
||||
ColumnMapping map[string]string // map columns
|
||||
Joins []Join
|
||||
Joins []join
|
||||
Preloads map[string][]interface{}
|
||||
Settings sync.Map
|
||||
ConnPool ConnPool
|
||||
@ -49,7 +49,7 @@ type Statement struct {
|
||||
scopes []func(*DB) *DB
|
||||
}
|
||||
|
||||
type Join struct {
|
||||
type join struct {
|
||||
Name string
|
||||
Conds []interface{}
|
||||
On *clause.Where
|
||||
@ -538,7 +538,7 @@ func (stmt *Statement) clone() *Statement {
|
||||
}
|
||||
|
||||
if len(stmt.Joins) > 0 {
|
||||
newStmt.Joins = make([]Join, len(stmt.Joins))
|
||||
newStmt.Joins = make([]join, len(stmt.Joins))
|
||||
copy(newStmt.Joins, stmt.Joins)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ require (
|
||||
gorm.io/driver/postgres v1.5.9
|
||||
gorm.io/driver/sqlite v1.5.6
|
||||
gorm.io/driver/sqlserver v1.5.3
|
||||
gorm.io/gorm v1.25.10
|
||||
gorm.io/gorm v1.25.11
|
||||
)
|
||||
|
||||
require (
|
||||
|
Loading…
x
Reference in New Issue
Block a user