DDC-596: Add @DiscriminatorMap validation to orm:validate-schema #728

Closed
opened 2026-01-22 12:48:17 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (May 17, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user mjh_ca:

Assuming that all child classes of an @InheritanceType("SINGLE_TABLE") and @InheritanceType("JOINED") table should be defined in the topmost parent's @DiscriminatorMap, it would be very helpful to add this validation to the CLI orm:valdiate-schema.

At present, if a child table is defined in the topmost table @DiscriminatorMap on a SINGLE_TABLE inheritance, then orm:validate-schema states that the mapping files are correct but then a Doctrine\DBAL\Schema\SchemaException is thrown. The same exception is also thrown for other schema-tool commands (such as 'create').

Haven't tested what happens on a JOINED table..

/****
 * @Entity @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"employee" = "Employee"})   // note, the second child table was accidentally omitted here
 */
class Person
{
    // ...
}

/****
 * @Entity
 */
class Employee extends Person
{
    // ...
}

/****
 * @Entity
 */
class Customer extends Person
{
    // ....
}

Schema tool commands (create, validate-schema) then throw:

  [Doctrine\DBAL\Schema\SchemaException]
  The table with name 'person' already exists.

... and orm:validate-schema actually says that the mapping is correct (which it obviously isn't) before throwing the exception:

[Mapping]  OK - The mapping files are correct.

  [Doctrine\DBAL\Schema\SchemaException]
  The table with name 'person' already exists.

Not critical since the mapping is obviously wrong here, but having this extra check in the validator could save a lot of debugging time. A duplicate table name error is confusing in this situation, and it seems wrong that the validate-schema command presently reports that the mapping files are correct when in fact the inheritance is broken.

Originally created by @doctrinebot on GitHub (May 17, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user mjh_ca: Assuming that all child classes of an @InheritanceType("SINGLE_TABLE") and @InheritanceType("JOINED") table should be defined in the topmost parent's @DiscriminatorMap, it would be very helpful to add this validation to the CLI orm:valdiate-schema. At present, if a child table is defined in the topmost table @DiscriminatorMap on a SINGLE_TABLE inheritance, then orm:validate-schema states that the mapping files are correct but then a Doctrine\DBAL\Schema\SchemaException is thrown. The same exception is also thrown for other schema-tool commands (such as 'create'). Haven't tested what happens on a JOINED table.. ``` /**** * @Entity @InheritanceType("SINGLE_TABLE") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"employee" = "Employee"}) // note, the second child table was accidentally omitted here */ class Person { // ... } /**** * @Entity */ class Employee extends Person { // ... } /**** * @Entity */ class Customer extends Person { // .... } ``` Schema tool commands (create, validate-schema) then throw: ``` [Doctrine\DBAL\Schema\SchemaException] The table with name 'person' already exists. ``` ... and orm:validate-schema actually says that the mapping is correct (which it obviously isn't) before throwing the exception: ``` [Mapping] OK - The mapping files are correct. [Doctrine\DBAL\Schema\SchemaException] The table with name 'person' already exists. ``` Not critical since the mapping is obviously wrong here, but having this extra check in the validator could save a lot of debugging time. A duplicate table name error is confusing in this situation, and it seems wrong that the validate-schema command presently reports that the mapping files are correct when in fact the inheritance is broken.
admin added the Improvement label 2026-01-22 12:48:17 +01:00
admin closed this issue 2026-01-22 12:48:19 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 17, 2010):

Comment created by romanb:

Note: Not *all* child classes must be specified, only those that are entities. You can have non-mapped as well as mapped-superclasses as subclasses as well.

@doctrinebot commented on GitHub (May 17, 2010): Comment created by romanb: Note: Not **all\* child classes must be specified, only those that are *entities**. You can have non-mapped as well as mapped-superclasses as subclasses as well.
Author
Owner

@doctrinebot commented on GitHub (Jun 30, 2010):

Comment created by @beberlei:

The validation task to perform here would be:

Throw a warning if there exists and entity that extends the Parentclass, is however not part of the DiscriminatorMap

@doctrinebot commented on GitHub (Jun 30, 2010): Comment created by @beberlei: The validation task to perform here would be: Throw a warning if there exists and entity that extends the Parentclass, is however not part of the DiscriminatorMap
Author
Owner

@doctrinebot commented on GitHub (Jul 10, 2010):

Comment created by @beberlei:

Implemented

@doctrinebot commented on GitHub (Jul 10, 2010): Comment created by @beberlei: Implemented
Author
Owner

@doctrinebot commented on GitHub (Jul 10, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jul 10, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#728