From 192826c4567e4f0ea0382d4d13160ac310798555 Mon Sep 17 00:00:00 2001 From: Marco Ronchese <8733504+emarj@users.noreply.github.com> Date: Fri, 16 Dec 2022 13:09:46 +0100 Subject: [PATCH] allow custom types as indexes when joining tables --- qrm/scan_context.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/qrm/scan_context.go b/qrm/scan_context.go index fa99b5a..02997eb 100644 --- a/qrm/scan_context.go +++ b/qrm/scan_context.go @@ -187,28 +187,30 @@ func (s *ScanContext) getGroupKeyInfo( field := structType.Field(i) fieldType := indirectType(field.Type) - if !isSimpleModelType(fieldType) { - if fieldType.Kind() != reflect.Struct { - continue - } - - subType := s.getGroupKeyInfo(fieldType, &field, typeVisited) - - if len(subType.indexes) != 0 || len(subType.subTypes) != 0 { - ret.subTypes = append(ret.subTypes, subType) - } - } else { - if isPrimaryKey(field, primaryKeyOverwrites) { - newTypeName, fieldName := getTypeAndFieldName(typeName, field) - - index := s.typeToColumnIndex(newTypeName, fieldName) - - if index < 0 { + if !isPrimaryKey(field, primaryKeyOverwrites) { + if !isSimpleModelType(fieldType) { + if fieldType.Kind() != reflect.Struct { continue } - ret.indexes = append(ret.indexes, index) + subType := s.getGroupKeyInfo(fieldType, &field, typeVisited) + + if len(subType.indexes) != 0 || len(subType.subTypes) != 0 { + ret.subTypes = append(ret.subTypes, subType) + } } + } else { + + newTypeName, fieldName := getTypeAndFieldName(typeName, field) + + index := s.typeToColumnIndex(newTypeName, fieldName) + + if index < 0 { + continue + } + + ret.indexes = append(ret.indexes, index) + } }