Merge branch 'master' into CaseInsensitiveSchemaFields
This commit is contained in:
commit
aa0e8e721c
@ -103,11 +103,11 @@ func preloadEntryPoint(db *gorm.DB, joins []string, relationships *schema.Relati
|
|||||||
joined = true
|
joined = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
joinNames := strings.SplitN(join, ".", 2)
|
join0, join1, cut := strings.Cut(join, ".")
|
||||||
if len(joinNames) == 2 {
|
if cut {
|
||||||
if _, ok := relationships.Relations[joinNames[0]]; ok && name == joinNames[0] {
|
if _, ok := relationships.Relations[join0]; ok && name == join0 {
|
||||||
joined = true
|
joined = true
|
||||||
nestedJoins = append(nestedJoins, joinNames[1])
|
nestedJoins = append(nestedJoins, join1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
gorm.go
8
gorm.go
@ -138,12 +138,16 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
|
|||||||
return isConfig && !isConfig2
|
return isConfig && !isConfig2
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var skipAfterInitialize bool
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
if opt != nil {
|
if opt != nil {
|
||||||
if applyErr := opt.Apply(config); applyErr != nil {
|
if applyErr := opt.Apply(config); applyErr != nil {
|
||||||
return nil, applyErr
|
return nil, applyErr
|
||||||
}
|
}
|
||||||
defer func(opt Option) {
|
defer func(opt Option) {
|
||||||
|
if skipAfterInitialize {
|
||||||
|
return
|
||||||
|
}
|
||||||
if errr := opt.AfterInitialize(db); errr != nil {
|
if errr := opt.AfterInitialize(db); errr != nil {
|
||||||
err = errr
|
err = errr
|
||||||
}
|
}
|
||||||
@ -195,6 +199,10 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
|
|||||||
if db, _ := db.DB(); db != nil {
|
if db, _ := db.DB(); db != nil {
|
||||||
_ = db.Close()
|
_ = db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DB is not initialized, so we skip AfterInitialize
|
||||||
|
skipAfterInitialize = true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.TranslateError {
|
if config.TranslateError {
|
||||||
|
@ -105,7 +105,7 @@ func parseFieldIndexes(field *Field) (indexes []Index, err error) {
|
|||||||
var (
|
var (
|
||||||
name string
|
name string
|
||||||
tag = strings.Join(v[1:], ":")
|
tag = strings.Join(v[1:], ":")
|
||||||
idx = strings.Index(tag, ",")
|
idx = strings.IndexByte(tag, ',')
|
||||||
tagSetting = strings.Join(strings.Split(tag, ",")[1:], ",")
|
tagSetting = strings.Join(strings.Split(tag, ",")[1:], ",")
|
||||||
settings = ParseTagSetting(tagSetting, ",")
|
settings = ParseTagSetting(tagSetting, ",")
|
||||||
length, _ = strconv.Atoi(settings["LENGTH"])
|
length, _ = strconv.Atoi(settings["LENGTH"])
|
||||||
|
@ -78,7 +78,7 @@ func (schema *Schema) parseRelation(field *Field) *Relationship {
|
|||||||
cacheStore := schema.cacheStore
|
cacheStore := schema.cacheStore
|
||||||
|
|
||||||
if relation.FieldSchema, err = getOrParse(fieldValue, cacheStore, schema.namer, schema.FieldsCaseInsensitive); err != nil {
|
if relation.FieldSchema, err = getOrParse(fieldValue, cacheStore, schema.namer, schema.FieldsCaseInsensitive); err != nil {
|
||||||
schema.err = err
|
schema.err = fmt.Errorf("failed to parse field: %s, error: %w", field.Name, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,6 +663,7 @@ func (rel *Relationship) ParseConstraint() *Constraint {
|
|||||||
if !(rel.References[idx].PrimaryKey == ref.PrimaryKey && rel.References[idx].ForeignKey == ref.ForeignKey &&
|
if !(rel.References[idx].PrimaryKey == ref.PrimaryKey && rel.References[idx].ForeignKey == ref.ForeignKey &&
|
||||||
rel.References[idx].PrimaryValue == ref.PrimaryValue) {
|
rel.References[idx].PrimaryValue == ref.PrimaryValue) {
|
||||||
matched = false
|
matched = false
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,7 +676,7 @@ func (rel *Relationship) ParseConstraint() *Constraint {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
name string
|
name string
|
||||||
idx = strings.Index(str, ",")
|
idx = strings.IndexByte(str, ',')
|
||||||
settings = ParseTagSetting(str, ",")
|
settings = ParseTagSetting(str, ",")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user