Skip to content

Commit

Permalink
Fixed incorrect metadata is being used for traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Oct 23, 2023
1 parent 49df802 commit b46f414
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/lib/Gateway/ExpressionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)),
));
}
Expand All @@ -244,15 +245,15 @@ private function handleRelationshipComparison(string $column, Comparison $compar
switch ($relationshipType) {
case DoctrineRelationship::class:
return $this->handleSubSelectQuery(
$relationshipMetadata,
$metadata,
$relationship->getForeignKeyColumn(),
$column,
$comparison->getValue(),
);
case DoctrineOneToManyRelationship::class:
case PreJoinedDoctrineRelationship::class:
return $this->handleJoinQuery(
$relationshipMetadata,
$metadata,
$column,
$comparison->getValue(),
);
Expand Down

0 comments on commit b46f414

Please sign in to comment.