@@ -1563,6 +1563,7 @@ public function mapManyEmbedded(array $mapping): void
1563
1563
{
1564
1564
$ mapping ['embedded ' ] = true ;
1565
1565
$ mapping ['type ' ] = self ::MANY ;
1566
+
1566
1567
$ this ->mapField ($ mapping );
1567
1568
}
1568
1569
@@ -1588,6 +1589,7 @@ public function mapManyReference(array $mapping): void
1588
1589
{
1589
1590
$ mapping ['reference ' ] = true ;
1590
1591
$ mapping ['type ' ] = self ::MANY ;
1592
+
1591
1593
$ this ->mapField ($ mapping );
1592
1594
}
1593
1595
@@ -2120,7 +2122,7 @@ public function getAssociationTargetClass($assocName): ?string
2120
2122
throw new InvalidArgumentException ("Association name expected, ' " . $ assocName . "' is not an association. " );
2121
2123
}
2122
2124
2123
- return $ this ->associationMappings [$ assocName ]['targetDocument ' ];
2125
+ return $ this ->associationMappings [$ assocName ]['targetDocument ' ] ?? null ;
2124
2126
}
2125
2127
2126
2128
/**
@@ -2170,6 +2172,14 @@ public function mapField(array $mapping): array
2170
2172
$ mapping ['fieldName ' ] = $ mapping ['name ' ];
2171
2173
}
2172
2174
2175
+ if ($ this ->isTypedProperty ($ mapping ['fieldName ' ])) {
2176
+ $ mapping = $ this ->validateAndCompleteTypedFieldMapping ($ mapping );
2177
+
2178
+ if (isset ($ mapping ['type ' ]) && $ mapping ['type ' ] === self ::MANY ) {
2179
+ $ mapping = $ this ->validateAndCompleteTypedManyAssociationMapping ($ mapping );
2180
+ }
2181
+ }
2182
+
2173
2183
if (! isset ($ mapping ['fieldName ' ]) || ! is_string ($ mapping ['fieldName ' ])) {
2174
2184
throw MappingException::missingFieldName ($ this ->name );
2175
2185
}
@@ -2242,14 +2252,6 @@ public function mapField(array $mapping): array
2242
2252
unset($ this ->generatorOptions ['type ' ]);
2243
2253
}
2244
2254
2245
- if ($ this ->isTypedProperty ($ mapping ['fieldName ' ])) {
2246
- $ mapping = $ this ->validateAndCompleteTypedFieldMapping ($ mapping );
2247
-
2248
- if (isset ($ mapping ['type ' ]) && ($ mapping ['type ' ] === self ::ONE || $ mapping ['type ' ] === self ::MANY )) {
2249
- $ mapping = $ this ->validateAndCompleteTypedAssociationMapping ($ mapping );
2250
- }
2251
- }
2252
-
2253
2255
if (! isset ($ mapping ['type ' ])) {
2254
2256
// Default to string
2255
2257
$ mapping ['type ' ] = Type::STRING ;
@@ -2653,19 +2655,15 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
2653
2655
*
2654
2656
* @return FieldMappingConfig
2655
2657
*/
2656
- private function validateAndCompleteTypedAssociationMapping (array $ mapping ): array
2658
+ private function validateAndCompleteTypedManyAssociationMapping (array $ mapping ): array
2657
2659
{
2658
2660
$ type = $ this ->reflClass ->getProperty ($ mapping ['fieldName ' ])->getType ();
2659
2661
2660
2662
if (! $ type instanceof ReflectionNamedType) {
2661
2663
return $ mapping ;
2662
2664
}
2663
2665
2664
- if (
2665
- ! isset ($ mapping ['collectionClass ' ])
2666
- && $ mapping ['type ' ] === self ::MANY
2667
- && class_exists ($ type ->getName ())
2668
- ) {
2666
+ if (! isset ($ mapping ['collectionClass ' ]) && class_exists ($ type ->getName ())) {
2669
2667
$ mapping ['collectionClass ' ] = $ type ->getName ();
2670
2668
}
2671
2669
0 commit comments