DDC-1510: Composite Primary Key Entities As Foreign Id #1896

Closed
opened 2026-01-22 13:30:05 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 25, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user goetas:

I have the following XML mapping.

<doctrine-mapping>
  <entity name="Role" table="role">
    <id name="module" type="string" column="module" association-key="true"/> <!-- association key + normal column as PK -->
    <id name="cod" type="string" column="cod"/>
    <field name="name" type="string" column="name"/>
    <one-to-one field="module" target-entity="Module">
      <join-columns>
        <join-column name="module" referenced-column-name="cod"/>
      </join-columns>
    </one-to-one>
  </entity>

  <entity  name="UserRole" table="user_role">

    <id name="roleModule" type="string" column="role_module" association-key="true"/>
    <id name="roleCod" type="string" column="role_cod" association-key="true"/> <!-- association key with two column -->

    <field name="name" type="string" column="name"/>

    <one-to-one field="roleModule" target-entity="Role">
      <join-columns>
        <join-column name="role_module" referenced-column-name="module"/>
        <join-column name="role_cod" referenced-column-name="cod"/>
      </join-columns>
    </one-to-one>
  </entity>
</doctrine-mapping>

As you can see, UserRole has an roleModule association that is an Identity through foreign Entities.

But Role PK is made by two column. One column is a string and a second column is another Identity through foreign Entities.

Currently ClassMetadataInfo::_validateAndCompleteAssociationMapping() do not allow composite keys with two or more join columns.
This behavior was added in DDC-117 (that is linked to 2d27a99a commit).

Inside validateAndCompleteAssociationMapping() there is this code.

if (count($mapping['joinColumns']) >= 2) {
    throw MappingException::cannotMapCompositePrimaryKeyEntitiesAsForeignId(
        $mapping['targetEntity'], $this->name, $mapping['fieldName']
    );
}

If i remove these lines, my code works and all tests passes successfully.

the current validateAndCompleteAssociationMapping() implementation does not respect http://www.doctrine-project.org/docs/orm/2.1/en/tutorials/composite-primary-keys.html#use-case-1-dynamic-attributes documentation section (Application\Model\ArticleAttribute entity uses the same approach).

Originally created by @doctrinebot on GitHub (Nov 25, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user goetas: I have the following XML mapping. ``` xml <doctrine-mapping> <entity name="Role" table="role"> <id name="module" type="string" column="module" association-key="true"/> <!-- association key + normal column as PK --> <id name="cod" type="string" column="cod"/> <field name="name" type="string" column="name"/> <one-to-one field="module" target-entity="Module"> <join-columns> <join-column name="module" referenced-column-name="cod"/> </join-columns> </one-to-one> </entity> <entity name="UserRole" table="user_role"> <id name="roleModule" type="string" column="role_module" association-key="true"/> <id name="roleCod" type="string" column="role_cod" association-key="true"/> <!-- association key with two column --> <field name="name" type="string" column="name"/> <one-to-one field="roleModule" target-entity="Role"> <join-columns> <join-column name="role_module" referenced-column-name="module"/> <join-column name="role_cod" referenced-column-name="cod"/> </join-columns> </one-to-one> </entity> </doctrine-mapping> ``` As you can see, UserRole has an roleModule association that is an Identity through foreign Entities. But Role PK is made by two column. One column is a string and a second column is another Identity through foreign Entities. Currently ClassMetadataInfo::_validateAndCompleteAssociationMapping() do not allow composite keys with two or more join columns. This behavior was added in [DDC-117](http://www.doctrine-project.org/jira/browse/DDC-117) (that is linked to 2d27a99a commit). Inside validateAndCompleteAssociationMapping() there is this code. ``` java if (count($mapping['joinColumns']) >= 2) { throw MappingException::cannotMapCompositePrimaryKeyEntitiesAsForeignId( $mapping['targetEntity'], $this->name, $mapping['fieldName'] ); } ``` If i remove these lines, my code works and all tests passes successfully. the current validateAndCompleteAssociationMapping() implementation does not respect http://www.doctrine-project.org/docs/orm/2.1/en/tutorials/composite-primary-keys.html#use-case-1-dynamic-attributes documentation section (Application\Model\ArticleAttribute entity uses the same approach).
admin added the Bug label 2026-01-22 13:30:05 +01:00
admin closed this issue 2026-01-22 13:30:05 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 15, 2011):

Comment created by @beberlei:

This is not supported and will never be, its to complicated to handle this internally.

There are at least 10 if not more locations in the code that will break on this.

@doctrinebot commented on GitHub (Dec 15, 2011): Comment created by @beberlei: This is not supported and will never be, its to complicated to handle this internally. There are at least 10 if not more locations in the code that will break on this.
Author
Owner

@doctrinebot commented on GitHub (Dec 15, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Dec 15, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1896