Combination of Joined and Single Table Inheritance Hierachy #7509

Open
opened 2026-01-22 15:52:35 +01:00 by admin · 0 comments
Owner

Originally created by @KevinHansen23 on GitHub (May 26, 2025).

Bug Report

Q A
Version 3.3.3

Summary

We have a combination of a parent class Document which is connected to the class DocumentInput via a joined table relationship. The DocumentInput class uses a single table inheritance and is extended by the DocumentInputOrder Class.

Here ist the relevant Configuration:


<?php

#[Entity]
#[Table(name: "documents")]
#[InheritanceType('JOINED')]
#[DiscriminatorColumn(name: 'documents_type', enumType: DocumentTypeDiscriminatorEnum::class)]
#[DiscriminatorMap([
    DocumentTypeDiscriminatorEnum::InputOrder->value => DocumentInput::class,
    //  more definitions
])]
class Document {
    // Property Definitions
}

#[Entity]
#[Table(name: "documents_inputs")]
#[InheritanceType('SINGLE_TABLE')]
#[DiscriminatorColumn(name: 'input_type', enumType: DocumentInputTypeDiscriminatorEnum::class)]
#[DiscriminatorMap([
    DocumentInputTypeDiscriminatorEnum::InputOrder->value => DocumentInputOrder::class,
    DocumentInputTypeDiscriminatorEnum::InputDeliveryNote->value => DocumentInputDeliveryNote::class,
    //  more definitions
])]
class DocumentInput extends Document {
    // Property Definitions
}

#[Entity]
class DocumentInputOrder extends DocumentInput {
    // Property Definitions
}

Current behavior

Using the findBy function leads directly to a Column not found error, where the missing column refers to the table from the Documents class:


return $this->doctrineService->getEntityManager()->getRepository(DocumentInputOrder::class)->findBy(
    criteria: ["customer" => $customer->getId()],
    limit: 10
);
// An exception occurred while executing a query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e0_.documents_id' in 'SELECT'

If we use the QueryBuilder and join manually to Documents we get a result, but it seems impossible to retrieve an object of type DocumentInputOrder. Only objects of type DocumentInput are returned:


$query = $this->doctrineService->getEntityManager()->createQueryBuilder()
    ->select("dio")
    ->from(DocumentInputOrder::class, "dio")
    ->leftJoin(Document::class, 'd', 'WITH', 'd.id = dio.id')
    ->setMaxResults($limit)
    ->getQuery();

return new ArrayCollection($query->getResult());

If we select from the Document::class and set an INSTANCE OF where Condition with the DocumentInputOrder::class the result set is empty.

Expected behavior

The findBy() method should not cause an Exception and the QueryBuilder should return Objects of the specified Type.

Originally created by @KevinHansen23 on GitHub (May 26, 2025). ### Bug Report | Q | A |-------------------------------------------- | ------ | Version | 3.3.3 #### Summary We have a combination of a parent class `Document` which is connected to the class `DocumentInput` via a joined table relationship. The `DocumentInput` class uses a single table inheritance and is extended by the `DocumentInputOrder` Class. Here ist the relevant Configuration: ```php <?php #[Entity] #[Table(name: "documents")] #[InheritanceType('JOINED')] #[DiscriminatorColumn(name: 'documents_type', enumType: DocumentTypeDiscriminatorEnum::class)] #[DiscriminatorMap([ DocumentTypeDiscriminatorEnum::InputOrder->value => DocumentInput::class, // more definitions ])] class Document { // Property Definitions } #[Entity] #[Table(name: "documents_inputs")] #[InheritanceType('SINGLE_TABLE')] #[DiscriminatorColumn(name: 'input_type', enumType: DocumentInputTypeDiscriminatorEnum::class)] #[DiscriminatorMap([ DocumentInputTypeDiscriminatorEnum::InputOrder->value => DocumentInputOrder::class, DocumentInputTypeDiscriminatorEnum::InputDeliveryNote->value => DocumentInputDeliveryNote::class, // more definitions ])] class DocumentInput extends Document { // Property Definitions } #[Entity] class DocumentInputOrder extends DocumentInput { // Property Definitions } ``` #### Current behavior Using the findBy function leads directly to a Column not found error, where the missing column refers to the table from the `Documents` class: ```php return $this->doctrineService->getEntityManager()->getRepository(DocumentInputOrder::class)->findBy( criteria: ["customer" => $customer->getId()], limit: 10 ); // An exception occurred while executing a query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e0_.documents_id' in 'SELECT' ``` If we use the QueryBuilder and join manually to Documents we get a result, but it seems impossible to retrieve an object of type DocumentInputOrder. Only objects of type DocumentInput are returned: ```php $query = $this->doctrineService->getEntityManager()->createQueryBuilder() ->select("dio") ->from(DocumentInputOrder::class, "dio") ->leftJoin(Document::class, 'd', 'WITH', 'd.id = dio.id') ->setMaxResults($limit) ->getQuery(); return new ArrayCollection($query->getResult()); ``` If we select from the `Document::class` and set an `INSTANCE OF` where Condition with the `DocumentInputOrder::class` the result set is empty. #### Expected behavior The `findBy()` method should not cause an Exception and the QueryBuilder should return Objects of the specified Type.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7509