forked from mirror/gorm
More compatible prioritized primary field #3156
This commit is contained in:
parent
b4166d9515
commit
53f8c9fc1c
|
@ -161,13 +161,18 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)
|
||||||
field.setupValuerAndSetter()
|
field.setupValuerAndSetter()
|
||||||
}
|
}
|
||||||
|
|
||||||
if f := schema.LookUpField("id"); f != nil {
|
prioritizedPrimaryField := schema.LookUpField("id")
|
||||||
if f.PrimaryKey {
|
if prioritizedPrimaryField == nil {
|
||||||
schema.PrioritizedPrimaryField = f
|
prioritizedPrimaryField = schema.LookUpField("ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
if prioritizedPrimaryField != nil {
|
||||||
|
if prioritizedPrimaryField.PrimaryKey {
|
||||||
|
schema.PrioritizedPrimaryField = prioritizedPrimaryField
|
||||||
} else if len(schema.PrimaryFields) == 0 {
|
} else if len(schema.PrimaryFields) == 0 {
|
||||||
f.PrimaryKey = true
|
prioritizedPrimaryField.PrimaryKey = true
|
||||||
schema.PrioritizedPrimaryField = f
|
schema.PrioritizedPrimaryField = prioritizedPrimaryField
|
||||||
schema.PrimaryFields = append(schema.PrimaryFields, f)
|
schema.PrimaryFields = append(schema.PrimaryFields, prioritizedPrimaryField)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue