add code to ignore duplicated column

This commit is contained in:
edv1n 2019-10-17 17:22:15 +02:00 committed by GitHub
parent d2007b3c82
commit 51ac582a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -617,6 +617,20 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
modelStruct.StructFields = append(modelStruct.StructFields, field) modelStruct.StructFields = append(modelStruct.StructFields, field)
} }
} }
// look for field which has tag COLUMN assigned, if found any, set other fields which has the same DBName to IsIgnored = true
for _, v := range modelStruct.StructFields {
if column, ok := v.TagSettingsGet("COLUMN"); ok {
for _, field := range modelStruct.StructFields {
if field == v {
continue
}
if field.DBName == column {
field.IsIgnored = true
}
}
}
}
if len(modelStruct.PrimaryFields) == 0 { if len(modelStruct.PrimaryFields) == 0 {
if field := getForeignField("id", modelStruct.StructFields); field != nil { if field := getForeignField("id", modelStruct.StructFields); field != nil {