DDC-3872: Using InheritanceType entity with orderBy in query facing error #4740

Open
opened 2026-01-22 14:48:36 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Aug 11, 2015).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user aistis:

If you have two classes like:

/****
 * Class User.
 *
 * @ORM\Entity
 * @ORM\Table(name="some_users")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string")
 * @ORM\DiscriminatorMap({"user"="User", "client"="UserClient"})
 */
class User extends BaseFosUserModel
{
    // some random logic
}
/****
 * Class UserClient.
 *
 * @ORM\Entity
 * @ORM\Table(name="some*user*clients")
 */
class UserClient extends User
{
    // some random logic
}

The following error is thrown:

{quote}
An exception has been thrown during the rendering of a template ("An exception occurred while executing 'SELECT DISTINCT id_14 FROM (SELECT c0_.username AS username_0, c0_.username_canonical AS username_canonical_1, c0_.email AS email_2, c0_.email_canonical AS email_canonical_3, c0_.enabled AS enabled_4, c0_.last_login AS last_login_5, c0_.locked AS locked_6, c0_.expired AS expired_7, c0_.expires_at AS expires_at_8, c0_.confirmation_token AS confirmation_token_9, c0_.password_requested_at AS password_requested_at_10, c0_.roles AS roles_11, c0_.credentials_expired AS credentials_expired_12, c0_.credentials_expire_at AS credentials_expire_at_13, c0_.id AS id_14, c0_.admin_locale AS admin_locale_15, c0_.password_changed AS password_changed_16, c0_.salt AS salt_17, c0_.password AS password_18, c1_.full_name AS full_name_19, c0_.discriminator AS discriminator_20 FROM some_user_clients c1_ INNER JOIN some_users c0_ ON c1_.id = c0_.id WHERE 1 = 1) dctrn_result ORDER BY c0_.email DESC LIMIT 20 OFFSET 0':

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'c0_.email' in 'order clause'") in SomeBundle::some.html.twig at line 10.
{quote}

It is caused by base entity subquery. The wrong c0_.email selector is used.

Originally created by @doctrinebot on GitHub (Aug 11, 2015). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user aistis: If you have two classes like: ``` php /**** * Class User. * * @ORM\Entity * @ORM\Table(name="some_users") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discriminator", type="string") * @ORM\DiscriminatorMap({"user"="User", "client"="UserClient"}) */ class User extends BaseFosUserModel { // some random logic } ``` ``` php /**** * Class UserClient. * * @ORM\Entity * @ORM\Table(name="some*user*clients") */ class UserClient extends User { // some random logic } ``` The following error is thrown: {quote} An exception has been thrown during the rendering of a template ("An exception occurred while executing 'SELECT DISTINCT id_14 FROM (SELECT c0_.username AS username_0, c0_.username_canonical AS username_canonical_1, c0_.email AS email_2, c0_.email_canonical AS email_canonical_3, c0_.enabled AS enabled_4, c0_.last_login AS last_login_5, c0_.locked AS locked_6, c0_.expired AS expired_7, c0_.expires_at AS expires_at_8, c0_.confirmation_token AS confirmation_token_9, c0_.password_requested_at AS password_requested_at_10, c0_.roles AS roles_11, c0_.credentials_expired AS credentials_expired_12, c0_.credentials_expire_at AS credentials_expire_at_13, c0_.id AS id_14, c0_.admin_locale AS admin_locale_15, c0_.password_changed AS password_changed_16, c0_.salt AS salt_17, c0_.password AS password_18, c1_.full_name AS full_name_19, c0_.discriminator AS discriminator_20 FROM some_user_clients c1_ INNER JOIN some_users c0_ ON c1_.id = c0_.id WHERE 1 = 1) dctrn_result ORDER BY c0_.email DESC LIMIT 20 OFFSET 0': SQLSTATE[42S22]: Column not found: 1054 Unknown column 'c0_.email' in 'order clause'") in SomeBundle::some.html.twig at line 10. {quote} It is caused by base entity subquery. The wrong `c0_.email` selector is used.
admin added the Bug label 2026-01-22 14:48:36 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 11, 2015):

Comment created by aistis:

I believe it is the same problem as http://stackoverflow.com/questions/29715104/error-with-orderby-column-not-found/30154357

@doctrinebot commented on GitHub (Aug 11, 2015): Comment created by aistis: I believe it is the same problem as http://stackoverflow.com/questions/29715104/error-with-orderby-column-not-found/30154357
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4740