allow custom types as indexes when joining tables

This commit is contained in:
Marco Ronchese 2022-12-16 13:09:46 +01:00
parent 4873e43cc5
commit 192826c456

View file

@ -187,6 +187,7 @@ func (s *ScanContext) getGroupKeyInfo(
field := structType.Field(i) field := structType.Field(i)
fieldType := indirectType(field.Type) fieldType := indirectType(field.Type)
if !isPrimaryKey(field, primaryKeyOverwrites) {
if !isSimpleModelType(fieldType) { if !isSimpleModelType(fieldType) {
if fieldType.Kind() != reflect.Struct { if fieldType.Kind() != reflect.Struct {
continue continue
@ -197,8 +198,9 @@ func (s *ScanContext) getGroupKeyInfo(
if len(subType.indexes) != 0 || len(subType.subTypes) != 0 { if len(subType.indexes) != 0 || len(subType.subTypes) != 0 {
ret.subTypes = append(ret.subTypes, subType) ret.subTypes = append(ret.subTypes, subType)
} }
}
} else { } else {
if isPrimaryKey(field, primaryKeyOverwrites) {
newTypeName, fieldName := getTypeAndFieldName(typeName, field) newTypeName, fieldName := getTypeAndFieldName(typeName, field)
index := s.typeToColumnIndex(newTypeName, fieldName) index := s.typeToColumnIndex(newTypeName, fieldName)
@ -208,7 +210,7 @@ func (s *ScanContext) getGroupKeyInfo(
} }
ret.indexes = append(ret.indexes, index) ret.indexes = append(ret.indexes, index)
}
} }
} }