From b46f414f3abc3815301ff485393ed6aa9f082a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 23 Oct 2023 10:25:14 +0200 Subject: [PATCH] Fixed incorrect metadata is being used for traversal --- src/lib/Gateway/ExpressionVisitor.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/Gateway/ExpressionVisitor.php b/src/lib/Gateway/ExpressionVisitor.php index e508f33..5793697 100644 --- a/src/lib/Gateway/ExpressionVisitor.php +++ b/src/lib/Gateway/ExpressionVisitor.php @@ -215,26 +215,27 @@ private function containsRelationshipDelimiter(string $column): bool */ private function handleRelationshipComparison(string $column, Comparison $comparison): string { + $metadata = $this->schemaMetadata; do { [ $foreignProperty, $column, ] = explode(self::RELATIONSHIP_DELIMITER, $column, 2); - $relationship = $this->schemaMetadata->getRelationshipByForeignProperty($foreignProperty); - $relationshipMetadata = $this->registry->getMetadata($relationship->getRelationshipClass()); + $relationship = $metadata->getRelationshipByForeignProperty($foreignProperty); + $metadata = $this->registry->getMetadata($relationship->getRelationshipClass()); } while ($this->containsRelationshipDelimiter($column)); - if (!$relationshipMetadata->hasColumn($column)) { + if (!$metadata->hasColumn($column)) { throw new RuntimeMappingException(sprintf( '"%s" does not exist as available column on "%s" class schema metadata. ' . 'Available columns: "%s". Available relationships: "%s"', $column, - $relationshipMetadata->getClassName(), - implode('", "', $relationshipMetadata->getColumns()), + $metadata->getClassName(), + implode('", "', $metadata->getColumns()), implode('", "', array_map( static fn (DoctrineRelationshipInterface $relationship): string => $relationship->getForeignProperty(), - $relationshipMetadata->getRelationships(), + $metadata->getRelationships(), )), )); } @@ -244,7 +245,7 @@ private function handleRelationshipComparison(string $column, Comparison $compar switch ($relationshipType) { case DoctrineRelationship::class: return $this->handleSubSelectQuery( - $relationshipMetadata, + $metadata, $relationship->getForeignKeyColumn(), $column, $comparison->getValue(), @@ -252,7 +253,7 @@ private function handleRelationshipComparison(string $column, Comparison $compar case DoctrineOneToManyRelationship::class: case PreJoinedDoctrineRelationship::class: return $this->handleJoinQuery( - $relationshipMetadata, + $metadata, $column, $comparison->getValue(), );