M
M
Maxim Barulin2017-12-04 11:41:54
symfony
Maxim Barulin, 2017-12-04 11:41:54

What is a discriminator column in doctrine?

Hello!
I'm trying to make an extension orm. But when inserting, the doctrine persistently tries to add a discriminator column to the database. Can someone explain why it is needed at all? And what is the right way to describe it?

AppBundle\Entity\BuildingObjectSuper:
    type: mappedSuperclass
    table: object
    fields:
        titleObject:
            type: text
            nullable: false
            length: 16777215
            options:
                fixed: false
            column: title_object

KRBundle\Entity\BuildingObject:
    type: entity
    inheritanceType: SINGLE_TABLE
    discriminatorColumn:
        name: titleObject
        type: string
    table: object
    repositoryClass: KRBundle\Repository\BuildingObjectRepository
    fields:
        other:
            type: integer
            nullable: true

the value from discriminatorColumn is persistently trying to insert into the database. And there is either
Column not found: 1054 Unknown column 'titleObject' in 'field list'

or
Duplicate definition of column 'column_name' on entity 'KRBundle\Entity\BuildingObject' in a field or discriminator column mapping.
if you specify an existing field

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2017-12-04
@Slavenin999

If you do just MappedSuperclass - then you don't need DiscriminatorColumn, you need it for other purposes

B
BoShurik, 2017-12-04
@BoShurik

docs.doctrine-project.org/projects/doctrine-orm/en... The
DiscriminatorColumn is added automatically, it doesn't need to be declared in the entity

D
Denis, 2017-12-04
@prototype_denis

Колонка дискриминатора - это служебный столбец для доктрины. На основе этого значения доктрина маппит данные из базы на определенный объект.
От него не нужно избавляться :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question