Trait metadata overriding fails for MappedSuperclass #5719

Open
opened 2026-01-22 15:15:29 +01:00 by admin · 0 comments
Owner

Originally created by @origaminal on GitHub (Sep 29, 2017).

If one will try to define some metadata in a trait and then to override this metadata in the MappedSuperclass that uses the trait he will fail in the case properties were not set as private. The issue is described on StackOverflow https://stackoverflow.com/questions/46354858/override-association-mapping-of-a-trait-property-in-doctrine-2-6

I wrote the test case that succeeds on the attempt to override a private property and fails on the attempt to override a protected property. 367b11b86d

The root of the issue is in the AnnotationDriver's code:
53245e8a73/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php (L277-L286)
It skips all non-private properties for a MappedSuperclass and therefore they do not appear in its metadata definition.

When the driver tries to do the overriding:
53245e8a73/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php (L478)
He fails to find the overridden property in the metadata and throws an exception.

Originally created by @origaminal on GitHub (Sep 29, 2017). If one will try to define some metadata in a trait and then to override this metadata in the `MappedSuperclass` that uses the trait he will fail in the case properties were not set as `private`. The issue is described on StackOverflow https://stackoverflow.com/questions/46354858/override-association-mapping-of-a-trait-property-in-doctrine-2-6 I wrote the test case that succeeds on the attempt to override a private property and fails on the attempt to override a protected property. https://github.com/origaminal/doctrine2/commit/367b11b86d136e45d0ec654c606511c34a9841dc The root of the issue is in the `AnnotationDriver`'s code: https://github.com/doctrine/doctrine2/blob/53245e8a73cb16d5e9ba35ffa5bbb15cc417bb9f/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L277-L286 It skips all non-private properties for a `MappedSuperclass` and therefore they do not appear in its metadata definition. When the driver tries to do the overriding: https://github.com/doctrine/doctrine2/blob/53245e8a73cb16d5e9ba35ffa5bbb15cc417bb9f/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L478 He fails to find the overridden property in the metadata and throws an exception.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5719