fix(09): WR-16 resolve model columns through embedded structs and explicit column tags
This commit is contained in:
@@ -785,21 +785,9 @@ func projectRecord(cc *CompiledController, model any) map[string]any {
|
||||
}
|
||||
|
||||
func modelColumns(model any) map[string]struct{} {
|
||||
t := reflect.TypeOf(model)
|
||||
for t != nil && t.Kind() == reflect.Pointer {
|
||||
t = t.Elem()
|
||||
}
|
||||
cols := map[string]struct{}{}
|
||||
if t == nil || t.Kind() != reflect.Struct {
|
||||
return cols
|
||||
}
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if field.PkgPath != "" {
|
||||
continue
|
||||
}
|
||||
name := gormColumn(field)
|
||||
if name != "" {
|
||||
for _, mf := range modelFields(reflect.TypeOf(model)) {
|
||||
if name := gormColumn(mf.Field); name != "" {
|
||||
cols[name] = struct{}{}
|
||||
}
|
||||
}
|
||||
@@ -873,9 +861,9 @@ func castPK(model any, n uint) any {
|
||||
if t == nil || t.Kind() != reflect.Struct {
|
||||
return n
|
||||
}
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if !strings.Contains(field.Tag.Get("gorm"), "primaryKey") {
|
||||
for _, mf := range modelFields(t) {
|
||||
field := mf.Field
|
||||
if !hasPrimaryKeyTag(field) {
|
||||
continue
|
||||
}
|
||||
switch field.Type.Kind() {
|
||||
|
||||
Reference in New Issue
Block a user