2424use Doctrine \ODM \MongoDB \Aggregation \Builder ;
2525use Doctrine \ODM \MongoDB \DocumentManager ;
2626use Doctrine \ODM \MongoDB \Mapping \MappingException ;
27- use Symfony \Component \PropertyAccess \PropertyAccess ;
2827
2928/**
3029 * @author Vincent Amstoutz <[email protected] > @@ -41,7 +40,6 @@ final class IriFilter implements FilterInterface, OpenApiParameterFilterInterfac
4140 public function apply (Builder $ aggregationBuilder , string $ resourceClass , ?Operation $ operation = null , array &$ context = []): void
4241 {
4342 $ parameter = $ context ['parameter ' ];
44- $ property = $ parameter ->getProperty ();
4543 $ value = $ parameter ->getValue ();
4644
4745 $ documentManager = $ this ->getManagerRegistry ()->getManagerForClass ($ resourceClass );
@@ -50,38 +48,12 @@ public function apply(Builder $aggregationBuilder, string $resourceClass, ?Opera
5048 }
5149
5250 $ classMetadata = $ documentManager ->getClassMetadata ($ resourceClass );
51+ $ property = $ parameter ->getProperty ();
5352 if (!$ classMetadata ->hasReference ($ property )) {
5453 return ;
5554 }
5655
57- $ mapping = $ classMetadata ->getFieldMapping ($ property );
58-
59- if (isset ($ mapping ['mappedBy ' ])) {
60- $ propertyAccessor = PropertyAccess::createPropertyAccessor ();
61- $ mappedByProperty = $ mapping ['mappedBy ' ];
62- $ identifier = '_id ' ;
63-
64- if (is_iterable ($ value )) {
65- $ ids = [];
66- foreach ($ value as $ v ) {
67- if ($ relatedDoc = $ propertyAccessor ->getValue ($ v , $ mappedByProperty )) {
68- $ ids [] = $ propertyAccessor ->getValue ($ relatedDoc , 'id ' );
69- }
70- }
71-
72- $ aggregationBuilder ->match ()->field ($ identifier )->in ($ ids );
73-
74- return ;
75- }
76-
77- if ($ relatedDoc = $ propertyAccessor ->getValue ($ value , $ mappedByProperty )) {
78- $ aggregationBuilder ->match ()->field ($ identifier )->equals ($ propertyAccessor ->getValue ($ relatedDoc , 'id ' ));
79- }
80-
81- return ;
82- }
83-
84- $ method = $ classMetadata ->isCollectionValuedAssociation ($ property ) ? 'includesReferenceTo ' : 'references ' ;
56+ $ method = $ classMetadata ->isSingleValuedAssociation ($ property ) ? 'references ' : 'includesReferenceTo ' ;
8557
8658 if (is_iterable ($ value )) {
8759 $ match = $ aggregationBuilder ->match ();
0 commit comments