DDC-3369: Association Entity primary key composite with foreign keys #4161

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

Originally created by @doctrinebot on GitHub (Nov 4, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user SayDevNet:

Impossible to make an association between two entities in the following cases:

Entity1 with a composite primary key :
key1 (PK)
key2 (PK)

Entity2 with a composite primary key (with foreign key) :
key1 (PK FK)
key2 (PK FK)
key3 (PK)

How to connect two entities with this scenario?

Originally created by @doctrinebot on GitHub (Nov 4, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user SayDevNet: Impossible to make an association between two entities in the following cases: Entity1 with a composite primary key : key1 (PK) key2 (PK) Entity2 with a composite primary key (with foreign key) : key1 (PK FK) key2 (PK FK) key3 (PK) How to connect two entities with this scenario?
admin added the BugCan't FixInvalid labels 2026-01-22 14:36:23 +01:00
admin closed this issue 2026-01-22 14:36:23 +01:00
Author
Owner

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

Comment created by @ocramius:

This actually works as long as key1, key2 and key3 are user-generated values (such as UUIDs). We cannot support the case when these values are db-side generated.

@doctrinebot commented on GitHub (Nov 5, 2014): Comment created by @ocramius: This actually works as long as `key1`, `key2` and `key3` are user-generated values (such as UUIDs). We cannot support the case when these values are db-side generated.
Author
Owner

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

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Nov 5, 2014): Issue was closed with resolution "Invalid"
Author
Owner

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

Comment created by SayDevNet:

Can we get around this problem ?

@doctrinebot commented on GitHub (Nov 5, 2014): Comment created by SayDevNet: Can we get around this problem ?
Author
Owner

@maks-rafalko commented on GitHub (Apr 28, 2017):

@Ocramius Actually, this does not work:

[Doctrine\ORM\Mapping\MappingException]
  It is not possible to map entity 'Vehicle' with a composite primary key as part of the primary key of another entity 'PriceList#vehicle'.

And there is explicit condition for this case in 24377156b4/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php (L1485)

Should it be reopened?

@maks-rafalko commented on GitHub (Apr 28, 2017): @Ocramius Actually, this does not work: ``` [Doctrine\ORM\Mapping\MappingException] It is not possible to map entity 'Vehicle' with a composite primary key as part of the primary key of another entity 'PriceList#vehicle'. ``` And there is explicit condition for this case in https://github.com/doctrine/doctrine2/blob/24377156b41a5fca37b26579c28f824f779d41ef/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L1485 Should it be reopened?
Author
Owner

@maks-rafalko commented on GitHub (Apr 28, 2017):

Found an official answer that this is impossible https://github.com/doctrine/doctrine2/issues/6355#issuecomment-289158628

@maks-rafalko commented on GitHub (Apr 28, 2017): Found an official answer that this is impossible https://github.com/doctrine/doctrine2/issues/6355#issuecomment-289158628
Author
Owner

@lcobucci commented on GitHub (Apr 29, 2017):

@borNfreee thanks for linking to the comment, I'll apply the same tags here.

@lcobucci commented on GitHub (Apr 29, 2017): @borNfreee thanks for linking to the comment, I'll apply the same tags here.
Author
Owner

@maks-rafalko commented on GitHub (Apr 29, 2017):

@lcobucci would you be interested if I provide a documentation PR with noticing about this limitation?

@maks-rafalko commented on GitHub (Apr 29, 2017): @lcobucci would you be interested if I provide a documentation PR with noticing about this limitation?
Author
Owner

@lcobucci commented on GitHub (Apr 29, 2017):

@borNfreee sure, it would be great!

@lcobucci commented on GitHub (Apr 29, 2017): @borNfreee sure, it would be great!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4161