TLDR; Doctrine2: I need to know if it is possible to make a field within an Embeddable into a Primary Key from the Parent Entities (or MappedSuperclass') mapping. I already know how to set the primary key from the Embeddable's mapping, but this is not ideal (see "The Long Version").
The Long Version; I am trying to create Identity Value Objects for my Entities using Doctrine2 Embeddables.
Here is my problem...
I have two different Embeddables (MyEntityId and OtherEntityId) in an Entity (MyEntity).
I want a field within MyEntityId to be MyEntity's primary key.
As I have two identity embeddables in the same entity I want to define the primary key field in the entity mapping file rather than the embeddable mapping.
If I define the Primary Key from within the embeddable I run into problems when I want to do the same for OtherEntityId (as I am using it elsewhere).
Mapping the primary key in MyEntityId and OtherEntityId leads to MyEntity having a composite key, which I don't want.
Here are my mappings at the moment...
MyEntity:
embedded:
MyEntityId:
class: 'MyEntityId'
columnPrefix: false
OtherEntityId:
class: 'OtherEntityId'
columnPrefix: false
MyEntityId:
type: 'embeddable'
id:
id:
column: 'MyEntityId'
type: 'string'
OtherEntityId:
type: 'embeddable'
id:
id:
column: 'OtherEntityId'
type: 'string'
Solutions?
Create two seperate Embeddables to represent the same Id Value Object (not very dry and too complex)
Map the Embeddable's Primary Key field from the entity (is this possible? I can't find it anywhere in documentation)