Set the nested field as the primary key from parent entity mapping - Doctrine2

TL; DR; Doctrine2: I need to know if it is possible to create a field inside the key embedded in the main key from the parent object mapping (or MappedSuperclass). I already know how to set the primary key from Embeddable mapping, but this is not ideal (see "Long version").

Long version; I am trying to create identifier value objects for my objects using Doctrine2 Embeddables.

Here is my problem ...

  • I have two different file attachments (MyEntityId and OtherEntityId) in Entity (MyEntity).

  • I want the field in MyEntityId to be the primary key of MyEntity.

  • Since I have two identity attachments in the same object, I want to define the primary key field in the entity mapping file, not the inline mapping.

  • If I define a primary key from an embedded embeddable, I run into problems when I want to do the same for OtherEntityId (since I use it elsewhere).

  • Mapping the primary key in MyEntityId and OtherEntityId causes MyEntity to have a composite key that I don't need.

Here are my displays 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 separate inserts to represent the same Identity (not too dry and too complex)

  • Map the Embeddable Primary Key field from the object (is this possible? I cannot find it anywhere in the documentation)

+8
php doctrine2
source share
1 answer

According to the Doctrine 2 documentation:

Attached files can only contain properties with a basic @Column mapping. http://doctrine-orm.readthedocs.org/en/latest/tutorials/embeddables.html

I don’t think that you can specify the @id property for nested, just basic simple fields, since they are some kind of container, not entities.

0
source share

All Articles