DDC-1284: Inheritance fails in JOIN query #1616

Closed
opened 2026-01-22 13:20:01 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 21, 2011).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user thetourist:

Hi!
Sorry for my english, I'm working on that.
I've this code:

/****
 * @Entity
 * @Table(name="entity") 
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="entityTypeId", type="smallint")
 * @DiscriminatorMap({0 = "Bank",  1 = "Dealer", 2 = "Debtor", 3 = "Repo", 4 = "Appraiser", 5 = "Transport"})
 */
class Entities
{
     /****
     * @Id @GeneratedValue
     * @Column(type="integer")
     * @var integer
     */
    protected $id;

   /****
     * @Column(type="string", length=40)
     * @var text
     */
    protected $name;

    ............................................................
    ............................................................
}

------------------------------------------------------------------------------------------------------------------------------------
/**** 
 * @Entity(repositoryClass="Model\Entity\Repository\DebtorRepository")
 * @Table(name="debtor") 
 */ 
class Debtor extends Entities{

}

------------------------------------------------------------------------------------------------------------------------------------

/****
 * @Entity(repositoryClass="Model\Entity\Repository\PlacementRepository")
 * @Table(name="placement")
 */
class Placement
{

    /****
     * @Id
     * @Column(type="smallint")
     * @var integer
     */
    protected $id;


       /****
     * @ManyToOne(targetEntity="Debtor", inversedBy="placements")
     * @JoinColumn(name="debtorId", referencedColumnName="id")
     */
    protected $debtor;

........................................
.......................................
}

The DQL query:

{quote}
"SELECT t1 FROM Model\Entity\Placement t1 INNER JOIN t1.debtor d WITH d.name = 'test' "
{quote}

fails and show the message
{quote}
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e2_.name' in 'on clause'"
{quote}
I hope somebody know how fix this, I can't fixing this.

Originally created by @doctrinebot on GitHub (Jul 21, 2011). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user thetourist: Hi! Sorry for my english, I'm working on that. I've this code: ``` java /**** * @Entity * @Table(name="entity") * @InheritanceType("JOINED") * @DiscriminatorColumn(name="entityTypeId", type="smallint") * @DiscriminatorMap({0 = "Bank", 1 = "Dealer", 2 = "Debtor", 3 = "Repo", 4 = "Appraiser", 5 = "Transport"}) */ class Entities { /**** * @Id @GeneratedValue * @Column(type="integer") * @var integer */ protected $id; /**** * @Column(type="string", length=40) * @var text */ protected $name; ............................................................ ............................................................ } ------------------------------------------------------------------------------------------------------------------------------------ /**** * @Entity(repositoryClass="Model\Entity\Repository\DebtorRepository") * @Table(name="debtor") */ class Debtor extends Entities{ } ------------------------------------------------------------------------------------------------------------------------------------ /**** * @Entity(repositoryClass="Model\Entity\Repository\PlacementRepository") * @Table(name="placement") */ class Placement { /**** * @Id * @Column(type="smallint") * @var integer */ protected $id; /**** * @ManyToOne(targetEntity="Debtor", inversedBy="placements") * @JoinColumn(name="debtorId", referencedColumnName="id") */ protected $debtor; ........................................ ....................................... } ``` The DQL query: {quote} "SELECT t1 FROM Model\Entity\Placement t1 INNER JOIN t1.debtor d WITH d.name = 'test' " {quote} fails and show the message {quote} "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e2_.name' in 'on clause'" {quote} I hope somebody know how fix this, I can't fixing this.
admin added the Bug label 2026-01-22 13:20:01 +01:00
admin closed this issue 2026-01-22 13:20:03 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 26, 2011):

Comment created by @beberlei:

Can you call $query->getSQL() and show me the generated SQL statement? or grab it from a log file

@doctrinebot commented on GitHub (Jul 26, 2011): Comment created by @beberlei: Can you call $query->getSQL() and show me the generated SQL statement? or grab it from a log file
Author
Owner

@doctrinebot commented on GitHub (Aug 14, 2011):

Comment created by @guilhermeblanco:

Hi,

This issue is impossible to be fixed by Doctrine side.
The inheritance requires Doctrine to make additional JOINs to also include the inherited Entities, but it's not possible at that stage to determine which JOIN-ON clause your WITH would be part of, it generates a broken SQL.

That's your situation. Since in your individual situation you're doing INNER JOINs, you are pretty much able to fix this by doing a WHERE clause. From Doctrine perspective, this issue is not fixable.

Cheers,

@doctrinebot commented on GitHub (Aug 14, 2011): Comment created by @guilhermeblanco: Hi, This issue is impossible to be fixed by Doctrine side. The inheritance requires Doctrine to make additional JOINs to also include the inherited Entities, but it's not possible at that stage to determine which JOIN-ON clause your WITH would be part of, it generates a broken SQL. That's your situation. Since in your individual situation you're doing INNER JOINs, you are pretty much able to fix this by doing a WHERE clause. From Doctrine perspective, this issue is not fixable. Cheers,
Author
Owner

@doctrinebot commented on GitHub (Aug 14, 2011):

Issue was closed with resolution "Can't Fix"

@doctrinebot commented on GitHub (Aug 14, 2011): Issue was closed with resolution "Can't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1616