mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Question if a PR on ClassMetadata mappings makes sense #7565
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @michaelKaefer on GitHub (Oct 21, 2025).
There are packages that use
ClassMetadatato programmatically generate entity forms or admin UIs. Examples are Symfony Doctrine bridge and EasyAdminBundle.The API for checking if an entity property is representing a) a field or b) an embedded class or c) an association is:
a) The API is not uniform and packages use:
isset($metadata->fieldMappings[$propertyName])-> to know if a property represents a field (and not an embeddable class)isset($metadata->embeddedClasses[$propertyName])-> to know if a property represents an embedded class (and not a field)$metadata->hasAssociation($propertyName)-> to know if a property represents an associationb) The API is confusing IMO:
$metadata->hasField($propertyName)returns true if there is no field mapping but an embedded class mapping (which I guess makes sense in some contexts but I didn't find such a context even though I searched for one and even if it exists two seperate checks can still be done there)I searched Doctrine's code and both methods
hasAssociationandhasFieldare not used often, most time theissetcheck is used.Would you accept a PR for ORM 2 that deprecates both methods and suggest to uniformly use the
issetcheck in all client code? (Also affects the interfaceDoctrine\Persistence\Mapping\ClassMetadata). So client code is never tempted to sometimes use the methods and sometimes use theissetway just because developers don't know what is the better way and if there is a better way at all.Or would you accept a refactoring PR for ORM 2 that deprecates 2 methods and adds 3 other methods? (Also in the interface
Doctrine\Persistence\Mapping\ClassMetadata).I would look forward to implement it and refactor existing usages but I guess changing an
interfaceis not very welcome. Maybe it's not worth the effort to do a PR? Thanks a lot for any answer.