[PR #9637] Fix exception message in "missingFieldName" MappingException method #11765

Closed
opened 2026-01-22 16:11:51 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/9637

State: closed
Merged: No


I encountered a legitimate MappingException with XML mapping :

In MappingException.php line 82:
The field or association mapping misses the 'fieldName' attribute in entity 'App\Modules\Athena\Model\OrbitalBase'

Indeed I used name attribute by mistake for my many-to-one relationship. So I apply the suggested change :

<many-to-one fieldName="rPlayer" target-entity="App\Modules\Zeus\Model\Player">
  <!-- ... -->
</many-to-one>

But then I still have the same error message. Comparing to the documentation, I find out that the real attribute to use is field. Once I replaced fieldName with it, it works ! But it seemed to me that the exception message was misleading.

I found out in ClassMetadataInfo.php that indeed we look for a fieldName key in the mapping data:

1ffb9152f7/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php (L1777-L1781)

Seemed that the mapping was modified when parsing the XML file. I found the culprit in XmlDriver.php:

1ffb9152f7/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php (L507-L509)

The same transformation is performed for one-to-one and many-to-many associations. As I suppose there's a reason to do it, I just changed in this PR the suggested correction in MappingException by replacing fieldName with field in the exception message.

I didn't found relevant to change the missingFieldName method to fit that change because missingField could imply something else imho.

**Original Pull Request:** https://github.com/doctrine/orm/pull/9637 **State:** closed **Merged:** No --- I encountered a legitimate ``MappingException`` with XML mapping : ``` In MappingException.php line 82: The field or association mapping misses the 'fieldName' attribute in entity 'App\Modules\Athena\Model\OrbitalBase' ``` Indeed I used `name` attribute by mistake for my `many-to-one` relationship. So I apply the suggested change : ```xml <many-to-one fieldName="rPlayer" target-entity="App\Modules\Zeus\Model\Player"> <!-- ... --> </many-to-one> ``` But then I still have the same error message. Comparing to the documentation, I find out that the real attribute to use is `field`. Once I replaced `fieldName` with it, it works ! But it seemed to me that the exception message was misleading. I found out in `ClassMetadataInfo.php` that indeed we look for a `fieldName` key in the mapping data: https://github.com/doctrine/orm/blob/1ffb9152f76bd3d332d5275bd2272d3984bcf3d6/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L1777-L1781 Seemed that the mapping was modified when parsing the XML file. I found the culprit in `XmlDriver.php`: https://github.com/doctrine/orm/blob/1ffb9152f76bd3d332d5275bd2272d3984bcf3d6/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php#L507-L509 The same transformation is performed for `one-to-one` and `many-to-many` associations. As I suppose there's a reason to do it, I just changed in this PR the suggested correction in `MappingException` by replacing `fieldName` with `field` in the exception message. I didn't found relevant to change the `missingFieldName` method to fit that change because `missingField` could imply something else imho.
admin added the pull-request label 2026-01-22 16:11:51 +01:00
admin closed this issue 2026-01-22 16:11:51 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#11765