DDC-3711: Error on manyToMany with composite primary key #4557

Closed
opened 2026-01-22 14:44:42 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 23, 2015).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user pantelm:

Hi,
I hope that I report in the right place.
I have an issue when I try to create an manyToMany association with an entity with a composite primary key.
The problem is that only one of the two key are create on the association table.

I also have manyToOne association that works fine.

Here are the mapping

Commune.orm.yml

AppDemo\ZoneBundle\Entity\Commune:
    type: entity
    table: ref_commune
    id:
        codeInsee:
            type: string
            nullable: false
            length: 5
            fixed: true
            column: commune*code*insee
        codePostal:
            type: string
            nullable: false
            length: 5
            fixed: true
            column: commune*code*postal
    fields:
        nom:
            type: string
            nullable: false
            length: 100
            fixed: false
            column: commune_nom
    manyToMany:
        zones:
            targetEntity: Zone
            joinTable:
                name: lnk*zone*commune
                joinColumns:
                    commune*code*insee:
                        referencedColumnName: commune*code*insee
                    commune*code*postal:
                        referencedColumnName: commune*code*postal
                inverseJoinColumns:
                    zone_id:
                        referencedColumnName: zone_idx

Zone.orm.yml

AppDemo\ZoneBundle\Entity\Zone:
    type: entity
    repositoryClass: AppDemo\ZoneBundle\Repository\ZoneRepository
    table: ref_zone
    id:
        idx:
            type: integer
            nullable: false
            unsigned: false
            comment: ''
            id: true
            column: zone_idx
            generator:
                strategy: IDENTITY
    fields:
        libelle:
            type: string
            nullable: false
            length: 30
            options:
                default: ''
                comment: 'Libelle de la Zone'
Originally created by @doctrinebot on GitHub (Apr 23, 2015). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user pantelm: Hi, I hope that I report in the right place. I have an issue when I try to create an manyToMany association with an entity with a composite primary key. The problem is that only one of the two key are create on the association table. I also have manyToOne association that works fine. Here are the mapping `Commune.orm.yml` ``` AppDemo\ZoneBundle\Entity\Commune: type: entity table: ref_commune id: codeInsee: type: string nullable: false length: 5 fixed: true column: commune*code*insee codePostal: type: string nullable: false length: 5 fixed: true column: commune*code*postal fields: nom: type: string nullable: false length: 100 fixed: false column: commune_nom manyToMany: zones: targetEntity: Zone joinTable: name: lnk*zone*commune joinColumns: commune*code*insee: referencedColumnName: commune*code*insee commune*code*postal: referencedColumnName: commune*code*postal inverseJoinColumns: zone_id: referencedColumnName: zone_idx ``` `Zone.orm.yml` ``` AppDemo\ZoneBundle\Entity\Zone: type: entity repositoryClass: AppDemo\ZoneBundle\Repository\ZoneRepository table: ref_zone id: idx: type: integer nullable: false unsigned: false comment: '' id: true column: zone_idx generator: strategy: IDENTITY fields: libelle: type: string nullable: false length: 30 options: default: '' comment: 'Libelle de la Zone' ```
admin added the Bug label 2026-01-22 14:44:42 +01:00
admin closed this issue 2026-01-22 14:44:42 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 23, 2015):

@doctrinebot commented on GitHub (Apr 23, 2015): - depends on [DDC-3972: [GH-1539] [DDC-3711] Correct Error on manyToMany with composite primary key](http://www.doctrine-project.org/jira/browse/DDC-3972)
Author
Owner

@doctrinebot commented on GitHub (Apr 23, 2015):

Comment created by @ocramius:

What if you simply leave out the joinColumns mappings? Check what comes out of the metadata there, then compare it to your metadata (dump it)

@doctrinebot commented on GitHub (Apr 23, 2015): Comment created by @ocramius: What if you simply leave out the `joinColumns` mappings? Check what comes out of the metadata there, then compare it to your metadata (dump it)
Author
Owner

@doctrinebot commented on GitHub (Apr 23, 2015):

Comment created by pantelm:

When I remove the JoinsColumns mapping, I get an error:

Column name id referenced for relation from AppBundle\Entity\Commune towards AppBundle\Entity\Zone does not exist.

How do I dump the metadata?

@doctrinebot commented on GitHub (Apr 23, 2015): Comment created by pantelm: When I remove the JoinsColumns mapping, I get an error: `Column name `id` referenced for relation from AppBundle\Entity\Commune towards AppBundle\Entity\Zone does not exist.` How do I dump the metadata?
Author
Owner

@doctrinebot commented on GitHub (Oct 27, 2015):

Comment created by pantelm:

I have found where the problem come from, it just two line in the Yaml driver that are not in the loops that create columns for the join table.
I want to do a pull request but I have trouble writing test.

@doctrinebot commented on GitHub (Oct 27, 2015): Comment created by pantelm: I have found where the problem come from, it just two line in the Yaml driver that are not in the loops that create columns for the join table. I want to do a pull request but I have trouble writing test.
Author
Owner

@doctrinebot commented on GitHub (Oct 31, 2015):

Comment created by pantelm:

I made a PR for this error
[https://github.com/doctrine/doctrine2/pull/1540]

@doctrinebot commented on GitHub (Oct 31, 2015): Comment created by pantelm: I made a PR for this error [https://github.com/doctrine/doctrine2/pull/1540]
Author
Owner

@doctrinebot commented on GitHub (Nov 8, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1540] was assigned:
https://github.com/doctrine/doctrine2/pull/1540

@doctrinebot commented on GitHub (Nov 8, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1540] was assigned: https://github.com/doctrine/doctrine2/pull/1540
Author
Owner

@doctrinebot commented on GitHub (Nov 8, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1540] was merged:
https://github.com/doctrine/doctrine2/pull/1540

@doctrinebot commented on GitHub (Nov 8, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1540] was merged: https://github.com/doctrine/doctrine2/pull/1540
Author
Owner

@Ocramius commented on GitHub (Aug 23, 2018):

Already handled in 2.4.7

@Ocramius commented on GitHub (Aug 23, 2018): Already handled in 2.4.7
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4557