[#5958] fixed RecordQuery() custom struct scanning

This commit is contained in:
Gani Georgiev
2024-11-26 14:13:32 +02:00
parent f1b199b35c
commit 6e26cb5d88
3 changed files with 47 additions and 14 deletions

View File

@@ -102,11 +102,6 @@ func (app *BaseApp) RecordQuery(collectionModelOrIdentifier any) *dbx.SelectQuer
return nil
default: // expects []RecordProxy slice
records, err := resolveRecordAllHook(collection, op)
if err != nil {
return err
}
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
return errors.New("must be a pointer")
@@ -118,11 +113,6 @@ func (app *BaseApp) RecordQuery(collectionModelOrIdentifier any) *dbx.SelectQuer
return errors.New("must be a slice of RecordSetters")
}
// create an empty slice
if rv.IsNil() {
rv.Set(reflect.MakeSlice(rv.Type(), 0, len(records)))
}
et := rv.Type().Elem()
var isSliceOfPointers bool
@@ -135,6 +125,16 @@ func (app *BaseApp) RecordQuery(collectionModelOrIdentifier any) *dbx.SelectQuer
return op(sliceA)
}
records, err := resolveRecordAllHook(collection, op)
if err != nil {
return err
}
// create an empty slice
if rv.IsNil() {
rv.Set(reflect.MakeSlice(rv.Type(), 0, len(records)))
}
for _, record := range records {
ev := reflect.New(et)