@@ -112,17 +112,21 @@ public function getTypes($class, $property, array $context = [])
112
112
if (isset ($ associationMapping ['indexBy ' ])) {
113
113
/** @var ClassMetadataInfo $subMetadata */
114
114
$ subMetadata = $ this ->classMetadataFactory ->getMetadataFor ($ associationMapping ['targetEntity ' ]);
115
- $ fieldName = $ subMetadata ->getFieldForColumn ($ associationMapping ['indexBy ' ]);
116
- $ typeOfField = $ subMetadata ->getTypeOfField ($ fieldName );
117
115
118
- // Maybe $fieldName is an association
119
- if (null === $ typeOfField ) {
120
- $ associationMapping = $ subMetadata ->getAssociationMapping ($ fieldName );
121
-
122
- /** @var ClassMetadataInfo $subMetadata */
123
- $ indexProperty = $ subMetadata ->getSingleAssociationReferencedJoinColumnName ($ fieldName );
124
- $ subMetadata = $ this ->classMetadataFactory ->getMetadataFor ($ associationMapping ['targetEntity ' ]);
125
- $ typeOfField = $ subMetadata ->getTypeOfField ($ indexProperty );
116
+ // Check if indexBy value is a property
117
+ $ fieldName = $ associationMapping ['indexBy ' ];
118
+ if (null === ($ typeOfField = $ subMetadata ->getTypeOfField ($ fieldName ))) {
119
+ $ fieldName = $ subMetadata ->getFieldForColumn ($ associationMapping ['indexBy ' ]);
120
+ //Not a property, maybe a column name?
121
+ if (null === ($ typeOfField = $ subMetadata ->getTypeOfField ($ fieldName ))) {
122
+ //Maybe the column name is the association join column?
123
+ $ associationMapping = $ subMetadata ->getAssociationMapping ($ fieldName );
124
+
125
+ /** @var ClassMetadataInfo $subMetadata */
126
+ $ indexProperty = $ subMetadata ->getSingleAssociationReferencedJoinColumnName ($ fieldName );
127
+ $ subMetadata = $ this ->classMetadataFactory ->getMetadataFor ($ associationMapping ['targetEntity ' ]);
128
+ $ typeOfField = $ subMetadata ->getTypeOfField ($ indexProperty );
129
+ }
126
130
}
127
131
128
132
if (!$ collectionKeyType = $ this ->getPhpType ($ typeOfField )) {
0 commit comments