-
-
Notifications
You must be signed in to change notification settings - Fork 515
Description
Bug Report
| Q | A |
|---|---|
| BC Break | yes |
| Version | 2.15.1 |
Summary
Using #[DiscriminatorValue] with custom value does not yield expected results. This was discovered when adding types to ClassMetadata and realized that discriminatorValue and defaultDiscriminatorValue are storing class-string, while discriminatorMap supports any string or int keys.
Current behavior
Following mapping:
#[ODM\MappedSuperclass]
#[ODM\DiscriminatorField('type')]
#[ODM\InheritanceType('SINGLE_COLLECTION')]
class GH2936Superclass
{
#[ODM\Id]
public ?string $id;
}
#[ODM\Document]
#[ODM\DiscriminatorValue('foo')]
class GH2936FooDocument extends GH2936Superclass
{
}Does not allow defining custom values for each document. While #[DiscriminatorValue] accepts a value, it currently has to be the FQCN of the document which defeats the purpose. Custom values can only be defined using #[DiscriminatorMap] at the moment.
How to reproduce
See following failing test: https://github.com/IonBazan/mongodb-odm/blob/test-discriminator-value/tests/Tests/Functional/Ticket/GH2936Test.php
Expected behavior
It should be possible to easily define additional discriminator mapping using child classes' #[DiscriminatorValue] attribute.
See also #644