DiscriminatorColumn fieldName is not set in AnnotationDriver #5909

Closed
opened 2026-01-22 15:21:47 +01:00 by admin · 5 comments
Owner

Originally created by @Zayon on GitHub (Mar 2, 2018).

In branch 2.6
Given I have an Entity :

/**
 * @ORM\Entity()
 * @ORM\Table(name="table")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="db_column", type="string", fieldName="fieldName")
 * @ORM\DiscriminatorMap({"foo" = "Bar"})
 */
abstract class MyEntity
{
}

Then I have :

dump($this->em->getClassMetadata(MyEntity::class)->discriminatorColumn);
array:5 [
  "name" => "db_column"
  "type" => "string"
  "length" => 255
  "columnDefinition" => null
  "fieldName" => "db_column" // Should be "fieldName"
]

Fix is :

$metadata->setDiscriminatorColumn(
    [
        'name'             => $discrColumnAnnot->name,
        'type'             => $discrColumnAnnot->type ?: 'string',
        'length'           => $discrColumnAnnot->length ?: 255,
        'columnDefinition' => $discrColumnAnnot->columnDefinition,
        'fieldName'        => $discrColumnAnnot->fieldName ?: $discrColumnAnnot->name,
    ]
);

In https://github.com/doctrine/doctrine2/blob/2.6/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L253

PR incoming
Edit : We only accept PRs to "master" well PR not incoming then. 😢

Originally created by @Zayon on GitHub (Mar 2, 2018). In branch 2.6 Given I have an Entity : ```php /** * @ORM\Entity() * @ORM\Table(name="table") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="db_column", type="string", fieldName="fieldName") * @ORM\DiscriminatorMap({"foo" = "Bar"}) */ abstract class MyEntity { } ``` Then I have : ```php dump($this->em->getClassMetadata(MyEntity::class)->discriminatorColumn); ``` ``` array:5 [ "name" => "db_column" "type" => "string" "length" => 255 "columnDefinition" => null "fieldName" => "db_column" // Should be "fieldName" ] ``` Fix is : ``` $metadata->setDiscriminatorColumn( [ 'name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type ?: 'string', 'length' => $discrColumnAnnot->length ?: 255, 'columnDefinition' => $discrColumnAnnot->columnDefinition, 'fieldName' => $discrColumnAnnot->fieldName ?: $discrColumnAnnot->name, ] ); ``` In https://github.com/doctrine/doctrine2/blob/2.6/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L253 PR incoming Edit : `We only accept PRs to "master"` well PR not incoming then. :cry:
admin closed this issue 2026-01-22 15:21:48 +01:00
Author
Owner

@Ocramius commented on GitHub (Mar 2, 2018):

Note that a discriminator has no real fieldName - should probably not
even exist...

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On Fri, Mar 2, 2018 at 11:36 AM, Pablo Godinez notifications@github.com
wrote:

In branch 2.6
Given I have an Entity :

/** * @ORM\Entity() * @ORM\Table(name="table") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="db_column", type="string", fieldName="fieldName") * @ORM\DiscriminatorMap({"foo" = "Bar"}) */abstract class MyEntity{}

Then I have :

dump($this->em->getClassMetadata(MyEntity::class)->discriminatorColumn);

array:5 [
"name" => "db_column"
"type" => "string"
"length" => 255
"columnDefinition" => null
"fieldName" => "db_column" // Should be "fieldName"
]

Fix is :

$metadata->setDiscriminatorColumn(
[
'name' => $discrColumnAnnot->name,
'type' => $discrColumnAnnot->type ?: 'string',
'length' => $discrColumnAnnot->length ?: 255,
'columnDefinition' => $discrColumnAnnot->columnDefinition,
'fieldName' => $discrColumnAnnot->fieldName ?: $discrColumnAnnot->name,
]
);

In https://github.com/doctrine/doctrine2/blob/2.6/lib/
Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L253

PR incoming


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/7106, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakJ_-AilPKg5TNCpDZ_sSR2IZC7cjks5taSCegaJpZM4SZtBe
.

@Ocramius commented on GitHub (Mar 2, 2018): Note that a discriminator has no real `fieldName` - should probably not even exist... Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On Fri, Mar 2, 2018 at 11:36 AM, Pablo Godinez <notifications@github.com> wrote: > In branch 2.6 > Given I have an Entity : > > /** * @ORM\Entity() * @ORM\Table(name="table") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="db_column", type="string", fieldName="fieldName") * @ORM\DiscriminatorMap({"foo" = "Bar"}) */abstract class MyEntity{} > > Then I have : > > dump($this->em->getClassMetadata(MyEntity::class)->discriminatorColumn); > > array:5 [ > "name" => "db_column" > "type" => "string" > "length" => 255 > "columnDefinition" => null > "fieldName" => "db_column" // Should be "fieldName" > ] > > Fix is : > > $metadata->setDiscriminatorColumn( > [ > 'name' => $discrColumnAnnot->name, > 'type' => $discrColumnAnnot->type ?: 'string', > 'length' => $discrColumnAnnot->length ?: 255, > 'columnDefinition' => $discrColumnAnnot->columnDefinition, > 'fieldName' => $discrColumnAnnot->fieldName ?: $discrColumnAnnot->name, > ] > ); > > In https://github.com/doctrine/doctrine2/blob/2.6/lib/ > Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L253 > > PR incoming > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/doctrine/doctrine2/issues/7106>, or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAJakJ_-AilPKg5TNCpDZ_sSR2IZC7cjks5taSCegaJpZM4SZtBe> > . >
Author
Owner

@Zayon commented on GitHub (Mar 5, 2018):

Well what I want to accomplish is to have a single repository that can return any of inherited class.

like this:

$instance = $this->myEntityRepository->findOneBy([
    'discriminatorFieldName' => 'foo'
    'someField' => 'someValue',
]);

echo get_class($instance); // 'Bar'

Anyway DiscriminatorColumn should either have a fieldName property correctly set or no fieldName property at all.

@Zayon commented on GitHub (Mar 5, 2018): Well what I want to accomplish is to have a single repository that can return any of inherited class. like this: ```php $instance = $this->myEntityRepository->findOneBy([ 'discriminatorFieldName' => 'foo' 'someField' => 'someValue', ]); echo get_class($instance); // 'Bar' ``` Anyway `DiscriminatorColumn` should either have a `fieldName` property correctly set or no `fieldName` property at all.
Author
Owner

@Ocramius commented on GitHub (Mar 5, 2018):

This won't work by design, because the discriminator is NOT a field. The fact that it has a field in the metadata is a different story, and IMO the fieldName should not exist at all there.

@guilhermeblanco maybe this is already fixed in master?

@Ocramius commented on GitHub (Mar 5, 2018): This won't work by design, because the discriminator is *NOT* a field. The fact that it has a field in the metadata is a different story, and IMO the `fieldName` should not exist at all there. @guilhermeblanco maybe this is already fixed in `master`?
Author
Owner

@guilhermeblanco commented on GitHub (Mar 5, 2018):

IIRC, I dropped the fieldName from DiscriminatorColumn already in master.

@guilhermeblanco commented on GitHub (Mar 5, 2018): IIRC, I dropped the `fieldName` from DiscriminatorColumn already in master.
Author
Owner

@beberlei commented on GitHub (Dec 7, 2020):

This seems to be dead code that was never used in 2.x

@beberlei commented on GitHub (Dec 7, 2020): This seems to be dead code that was never used in 2.x
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5909