DDC-3349: Possibility to override order of fields of composite ID produced by Mapping #4139

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

Originally created by @doctrinebot on GitHub (Oct 13, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user tiger-seo:

So, the problem is when the one needs to use association key in composite identifier; they are added in the end of the identifier array, which is clearly not always suitable in regards to performance.
For example, following mapping:

Acme\DemoBundle\Entity\PageLocalFans:
    type: entity
    id:
        date:
            type: date
        page:
            associationKey: true
        countryCode:
            type: string
            length: 2
    fields:
        fans:
            type: integer
    manyToOne:
        page:
            targetEntity: Page
            joinColumn:
                name: page_id
                referencedColumnName: id
                onDelete: CASCADE

will turn into sql as:

CREATE TABLE page*local*fans (
  date         DATE       NOT NULL,
  country_code VARCHAR(2) NOT NULL,
  page_id      INT        NOT NULL,
  fans         INT        NOT NULL,
  INDEX IDX*7391EB36C4663E4 (page*id),
  PRIMARY KEY (date, country*code, page*id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8*unicode*ci ENGINE = InnoDB;

and there is no way to change the order of the primary from PRIMARY KEY (date, country*code, page_id) to PRIMARY KEY (date, page_id, country*code)

Originally created by @doctrinebot on GitHub (Oct 13, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user tiger-seo: So, the problem is when the one needs to use association key in composite identifier; they are added in the end of the identifier array, which is clearly not always suitable in regards to performance. For example, following mapping: ``` Acme\DemoBundle\Entity\PageLocalFans: type: entity id: date: type: date page: associationKey: true countryCode: type: string length: 2 fields: fans: type: integer manyToOne: page: targetEntity: Page joinColumn: name: page_id referencedColumnName: id onDelete: CASCADE ``` will turn into sql as: ``` CREATE TABLE page*local*fans ( date DATE NOT NULL, country_code VARCHAR(2) NOT NULL, page_id INT NOT NULL, fans INT NOT NULL, INDEX IDX*7391EB36C4663E4 (page*id), PRIMARY KEY (date, country*code, page*id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8*unicode*ci ENGINE = InnoDB; ``` and there is no way to change the order of the primary from `PRIMARY KEY (date, country*code, page_id)` to `PRIMARY KEY (date, page_id, country*code)`
admin added the New FeatureWon't Fix labels 2026-01-22 14:35:57 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4139