Description
Symfony version(s) affected: 4.4.2
Description
I have some entities with a createdAt
property that is not nullable
and gets populated on prePersist
by a subscriber. Having auto mapping enabled, I have to disable it for that property by using the DisableAutoMapping
annotation, otherwise it gets a NotNull
constraint added (as it is not nullable
), but this is checked before persisting and so I won't be able to get a valid form for those objects. So far so correct. That's a case DisableAutoMapping
is meant for as the auto mapper cannot know about the prePersist logic.
But some of my entities use single table inheritance and the abstract parent class (superclass) has that createdAt
property with DisableAutoMapping
set. And now the concrete child classes inherit the createdAt
property and its Doctrine-related annotations, but the DisableAutoMapping
gets lost and so they get that NotNull
Constraint attached.
When I debug a little and have a look into the ClassMetadata
, I can see that the property of the superclass has a autoMappingStrategy
value of 2
(= disabled) and no Constraint added, while the property of the concrete class has a value of 0
and a Type
Constraint and a NotNull
Constraint added.
How to reproduce
I can build a reproducer, if needed.
If you have a setting with single-table-inheritance, the problem should be easily reproducible by adding a DisableAutoMapping
Annotation to a property which gets any auto mapped Constraints and observe that it is ignored for the subclasses (as those are still there, but should not).
Possible Solution
When I move the declaration of that property to (all) the concrete child classes, the DisableAutoMapping
annotation is respected again and the property gets no constraints attached.
Additional context
In fact, my createdAt
property is loaded via a Trait, so I first thought that this is the problem. But copying the Trait content to the class itself showed the same behavior.