DDC-858: orderBy on associations does not work with discriminator columns #1063

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

Originally created by @doctrinebot on GitHub (Nov 5, 2010).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user sebastian.hoitz:

When you specify a oneToMany or manyToMany association to be ordered by a discriminator column, Doctrine fails, giving this error:

C:\Users\Sebastian Hoitz\Documents\Entwicklung\kt_api\trunk\tools>doctrine orm:validate-schema
[Mapping] FAIL - The entity-class 'App_Model_Contact' mapping is invalid:

  • The association App_Model_Contact#attributes is ordered by a foreign field type that is not a field on the target entity App_Model_Contact_Attribute

But in some cases (think of attributes, for example) you would really need this.

Originally created by @doctrinebot on GitHub (Nov 5, 2010). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user sebastian.hoitz: When you specify a oneToMany or manyToMany association to be ordered by a discriminator column, Doctrine fails, giving this error: C:\Users\Sebastian Hoitz\Documents\Entwicklung\kt_api\trunk\tools>doctrine orm:validate-schema [Mapping] FAIL - The entity-class 'App_Model_Contact' mapping is invalid: - The association App_Model_Contact#attributes is ordered by a foreign field type that is not a field on the target entity App_Model_Contact_Attribute But in some cases (think of attributes, for example) you would really need this.
admin added the New Feature label 2026-01-22 13:00:43 +01:00
admin closed this issue 2026-01-22 13:00:44 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 5, 2010):

Comment created by sebastian.hoitz:

Changing ClassMetadataInfo::hasField to this would fix the issue:

public function hasField($fieldName)
{
    return isset($this->fieldMappings[$fieldName]) ](| $this->discriminatorColumn['name') == $fieldName;
}

But I'm not sure if this is the most elegant solution.

Correction: This only solves the doctrine orm:schema-validate error. It does not order correctly :(

@doctrinebot commented on GitHub (Nov 5, 2010): Comment created by sebastian.hoitz: Changing ClassMetadataInfo::hasField to this would fix the issue: ``` public function hasField($fieldName) { return isset($this->fieldMappings[$fieldName]) ](| $this->discriminatorColumn['name') == $fieldName; } ``` But I'm not sure if this is the most elegant solution. Correction: This only solves the doctrine orm:schema-validate error. It does not order correctly :(
Author
Owner

@doctrinebot commented on GitHub (Oct 16, 2011):

Comment created by @guilhermeblanco:

Discriminator columns should never be used from user perspective. Discriminators are a internal helper for ORM only.

If you want to achieve a similar thing, you should add your own type field and track it for yourself.

@doctrinebot commented on GitHub (Oct 16, 2011): Comment created by @guilhermeblanco: Discriminator columns should never be used from user perspective. Discriminators are a internal helper for ORM only. If you want to achieve a similar thing, you should add your own type field and track it for yourself.
Author
Owner

@doctrinebot commented on GitHub (Oct 16, 2011):

Issue was closed with resolution "Invalid"

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

No dependencies set.

Reference: doctrine/archived-orm#1063