fix(09): WR-16 resolve model columns through embedded structs and explicit column tags
This commit is contained in:
@@ -477,24 +477,14 @@ func relationFieldName(model any, relation string) (string, bool) {
|
||||
}
|
||||
|
||||
func primaryColumn(model any) string {
|
||||
t := reflect.TypeOf(model)
|
||||
for t != nil && t.Kind() == reflect.Pointer {
|
||||
t = t.Elem()
|
||||
}
|
||||
if t == nil || t.Kind() != reflect.Struct {
|
||||
return "id"
|
||||
}
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if field.PkgPath != "" {
|
||||
for _, mf := range modelFields(reflect.TypeOf(model)) {
|
||||
if !hasPrimaryKeyTag(mf.Field) {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(field.Tag.Get("gorm"), "primaryKey") {
|
||||
if name := gormColumn(field); name != "" {
|
||||
return name
|
||||
}
|
||||
return field.Name
|
||||
if name := gormColumn(mf.Field); name != "" {
|
||||
return name
|
||||
}
|
||||
return defaultColumnName(mf.Field)
|
||||
}
|
||||
return "id"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user