From 2de8a9614eca383569ad17bc8c3a29765338a061 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Mon, 26 Dec 2022 14:25:41 +0100 Subject: [PATCH] Add Fully-Qualified class name in UnrecognizedField exception to ease debugging --- .../Entity/BasicEntityPersister.php | 6 +++--- .../Exception/UnrecognizedField.php | 7 +++++++ .../Exception/UnrecognizedFieldTest.php | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6e6877e8952..0b655254dfd 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -487,7 +487,7 @@ final protected function updateTable( $targetType = PersisterHelper::getTypeOfField($targetMapping->identifier[0], $targetMapping, $this->em); if ($targetType === []) { - throw UnrecognizedField::byName($targetMapping->identifier[0]); + throw UnrecognizedField::byFullyQualifiedName($this->class->name, $targetMapping->identifier[0]); } $types[] = reset($targetType); @@ -1199,7 +1199,7 @@ final protected function getOrderBySQL(array $orderBy, string $baseTableAlias): continue; } - throw UnrecognizedField::byName($fieldName); + throw UnrecognizedField::byFullyQualifiedName($this->class->name, $fieldName); } return ' ORDER BY ' . implode(', ', $orderByList); @@ -1757,7 +1757,7 @@ private function getSelectConditionStatementColumnSQL( return [$field]; } - throw UnrecognizedField::byName($field); + throw UnrecognizedField::byFullyQualifiedName($this->class->name, $field); } /** diff --git a/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php b/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php index dd89fde1a4b..a0e090ba092 100644 --- a/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php +++ b/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php @@ -10,8 +10,15 @@ final class UnrecognizedField extends PersisterException { + /** @deprecated This method is deprecated and will be removed in Doctrine ORM 3.0. Use {@see byFullyQualifiedName} instead */ public static function byName(string $field): self { return new self(sprintf('Unrecognized field: %s', $field)); } + + /** @param class-string $className */ + public static function byFullyQualifiedName(string $className, string $field): self + { + return new self(sprintf('Unrecognized field: %s::%s', $className, $field)); + } } diff --git a/tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php b/tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php new file mode 100644 index 00000000000..2f3b7b78013 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php @@ -0,0 +1,20 @@ +