Using ColumnMapping instead of a new map
This commit is contained in:
parent
a4270cc29d
commit
2444fc0d82
@ -40,9 +40,12 @@ func BuildQuerySQL(db *gorm.DB) {
|
||||
}
|
||||
}
|
||||
|
||||
if db.Statement.TruncatedAliases == nil {
|
||||
db.Statement.TruncatedAliases = make(map[string]string)
|
||||
truncatedTableAliases := make(map[string]string)
|
||||
|
||||
if db.Statement.ColumnMapping == nil {
|
||||
db.Statement.ColumnMapping = make(map[string]string)
|
||||
}
|
||||
|
||||
if db.Statement.SQL.Len() == 0 {
|
||||
db.Statement.SQL.Grow(100)
|
||||
clauseSelect := clause.Select{Distinct: db.Statement.Distinct}
|
||||
@ -168,10 +171,10 @@ func BuildQuerySQL(db *gorm.DB) {
|
||||
Alias: aliasName,
|
||||
})
|
||||
origTableAliasName := tableAliasName
|
||||
if alias, ok := db.Statement.TruncatedAliases[tableAliasName]; ok {
|
||||
if alias, ok := truncatedTableAliases[tableAliasName]; ok {
|
||||
origTableAliasName = alias
|
||||
}
|
||||
db.Statement.TruncatedAliases[aliasName] = utils.NestedRelationName(origTableAliasName, s)
|
||||
db.Statement.ColumnMapping[aliasName] = utils.NestedRelationName(origTableAliasName, s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +259,7 @@ func BuildQuerySQL(db *gorm.DB) {
|
||||
fullName = curAliasName
|
||||
}
|
||||
aliasName := db.NamingStrategy.JoinNestedRelationNames(nameParts)
|
||||
db.Statement.TruncatedAliases[aliasName] = fullName
|
||||
truncatedTableAliases[aliasName] = fullName
|
||||
curAliasName = aliasName
|
||||
|
||||
if _, ok := specifiedRelationsName[curAliasName]; !ok {
|
||||
|
3
scan.go
3
scan.go
@ -227,9 +227,6 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
|
||||
if sch != nil {
|
||||
matchedFieldCount := make(map[string]int, len(columns))
|
||||
for idx, column := range columns {
|
||||
if origName, ok := db.Statement.TruncatedAliases[column]; ok {
|
||||
column = origName
|
||||
}
|
||||
if field := sch.LookUpField(column); field != nil && field.Readable {
|
||||
fields[idx] = field
|
||||
if count, ok := matchedFieldCount[column]; ok {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"regexp"
|
||||
@ -156,18 +155,7 @@ func (ns NamingStrategy) formatName(prefix, table, name string) string {
|
||||
prefix, table, name,
|
||||
}, "_"), ".", "_")
|
||||
|
||||
if ns.IdentifierMaxLength == 0 {
|
||||
ns.IdentifierMaxLength = 64
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(formattedName) > ns.IdentifierMaxLength {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(formattedName))
|
||||
bs := h.Sum(nil)
|
||||
|
||||
formattedName = formattedName[0:ns.IdentifierMaxLength-8] + hex.EncodeToString(bs)[:8]
|
||||
}
|
||||
return formattedName
|
||||
return ns.truncateName(formattedName)
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -47,7 +47,6 @@ type Statement struct {
|
||||
attrs []interface{}
|
||||
assigns []interface{}
|
||||
scopes []func(*DB) *DB
|
||||
TruncatedAliases map[string]string
|
||||
Result *result
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user