DDC-1648: Primary Keys as Foreign Keys - still not working in Reverse Engineering in 2.1.6 #2073

Closed
opened 2026-01-22 13:39:35 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 12, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user rivaros:

Please, read this old thread - looks like this problem still is not solved :(

http://comments.gmane.org/gmane.comp.php.symfony.symfony2/1398

The primary key as foreign key limitation is from the 2.0 manual. You are using 2.1 with symfony, which supports this. Please use the correct manual.

The only problem is that the reverse engineering does not support this. You have to reverse engineer yourself, or write a patch to have Doctrine support this. I would really appreciate it

As I understand it is supported in the "core", but some reverse engineer script is still not using that possibility.
Could you at least point where this can fixed?

Originally created by @doctrinebot on GitHub (Feb 12, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user rivaros: Please, read this old thread - looks like this problem still is not solved :( http://comments.gmane.org/gmane.comp.php.symfony.symfony2/1398 > > The primary key as foreign key limitation is from the 2.0 manual. You are using 2.1 with symfony, which supports this. Please use the correct manual. > > > > The only problem is that the reverse engineering does not support this. You have to reverse engineer yourself, or write a patch to have Doctrine support this. I would really appreciate it As I understand it is supported in the "core", but some reverse engineer script is still not using that possibility. Could you at least point where this can fixed?
admin added the Bug label 2026-01-22 13:39:35 +01:00
admin closed this issue 2026-01-22 13:39:35 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 12, 2012):

Comment created by @beberlei:

In lib/Doctrine/ORM/Mapping/DatabaseDriver.php

@doctrinebot commented on GitHub (Feb 12, 2012): Comment created by @beberlei: In lib/Doctrine/ORM/Mapping/DatabaseDriver.php
Author
Owner

@doctrinebot commented on GitHub (Feb 12, 2012):

Comment created by rivaros:

Thank you Benjamin,

Actually started tracking this error from /lib/Doctrine/ORM/Mapping/ClasMetadataInfo.php and step-bystep it goes to
/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php

Actually it calls ClasMetadataInfo::mapMayToOne instead of mapOneToOne in such situations.
Will investigate further. Pff... DatabaseDriver.php looks a hard class. :)

@doctrinebot commented on GitHub (Feb 12, 2012): Comment created by rivaros: Thank you Benjamin, Actually started tracking this error from /lib/Doctrine/ORM/Mapping/ClasMetadataInfo.php and step-bystep it goes to /lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php Actually it calls ClasMetadataInfo::mapMayToOne instead of mapOneToOne in such situations. Will investigate further. Pff... DatabaseDriver.php looks a hard class. :)
Author
Owner

@doctrinebot commented on GitHub (Feb 12, 2012):

Comment created by rivaros:

I am almost done with it - need a little more help from you:

So I fixed the DatabaseDriver so it correctly calls mapOneToOne
and passes association_mapping to it.

    /****
     * Adds a one-to-one mapping.
     *
     * @param array $mapping The mapping.
     */
    public function mapOneToOne(array $mapping)
    {
        $mapping['type'] = self::ONE*TO*ONE;
        $mapping = $this->_validateAndCompleteOneToOneMapping($mapping);
        $this->_storeAssociationMapping($mapping);
print_r($assocMapping); <--added this to see what structure we have on output
    }

this gives the following structure

Array
(
    [fieldName] => someguid                      <--- my primary key field, which is also foreign key
    [targetEntity] => Additionalinfo               <--- target table
    [id] => 1                                                      <--- indicates that this mapping is also id (primary key)
    [joinColumns] => Array
        (
            [0] => Array
                (
                    [name] => Someguid                                                     <--- join columns
                    [referencedColumnName] => UniqueID                    
                )

        )

    [type] => 1  <-- indicates ONE-TO-ONE assoc mapping
    [mappedBy] => 
    [inversedBy] => 
    [isOwningSide] => 1
    [sourceEntity] => Sampledata
    [fetch] => 2
..... (i omit other data as not important)
)

Now the problem: in my entity I got the following

    /****
     * @var Additionalinfo
     *
     * @ORM\OneToOne(targetEntity="Additionalinfo")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Someguid", referencedColumnName="UniqueID")
     * })
     */
    private $someguid;

So it correctly created a One-To-One mapping, but it did not preserve @Id attribute.

I guess this is because field_associations and mapping_associations are processed in separate way,
and in mapping_association it ignores the $mapping["id"] setting.

Do you know what code is managing creating the <id ....> / @Id staff - it is common for annotation/yaml/xml, e.x. when i generated xml for entity, it also does not contain tag.

@doctrinebot commented on GitHub (Feb 12, 2012): Comment created by rivaros: I am almost done with it - need a little more help from you: So I fixed the DatabaseDriver so it correctly calls mapOneToOne and passes association_mapping to it. ``` /**** * Adds a one-to-one mapping. * * @param array $mapping The mapping. */ public function mapOneToOne(array $mapping) { $mapping['type'] = self::ONE*TO*ONE; $mapping = $this->_validateAndCompleteOneToOneMapping($mapping); $this->_storeAssociationMapping($mapping); print_r($assocMapping); <--added this to see what structure we have on output } ``` this gives the following structure ``` Array ( [fieldName] => someguid <--- my primary key field, which is also foreign key [targetEntity] => Additionalinfo <--- target table [id] => 1 <--- indicates that this mapping is also id (primary key) [joinColumns] => Array ( [0] => Array ( [name] => Someguid <--- join columns [referencedColumnName] => UniqueID ) ) [type] => 1 <-- indicates ONE-TO-ONE assoc mapping [mappedBy] => [inversedBy] => [isOwningSide] => 1 [sourceEntity] => Sampledata [fetch] => 2 ..... (i omit other data as not important) ) ``` Now the problem: in my entity I got the following ``` /**** * @var Additionalinfo * * @ORM\OneToOne(targetEntity="Additionalinfo") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="Someguid", referencedColumnName="UniqueID") * }) */ private $someguid; ``` So it correctly created a One-To-One mapping, but it did not preserve @Id attribute. I guess this is because field_associations and mapping_associations are processed in separate way, and in mapping_association it ignores the $mapping["id"] setting. Do you know what code is managing creating the <id ....> / @Id staff - it is common for annotation/yaml/xml, e.x. when i generated xml for entity, it also does not contain <id > tag.
Author
Owner

@doctrinebot commented on GitHub (Feb 12, 2012):

Comment created by rivaros:

Update: fixed the last problem in Doctrine/ORM/Tools/EntityGenerator.php

Still has to be fixed in YAML/XML exporters - not very familiar with the syntax.

@doctrinebot commented on GitHub (Feb 12, 2012): Comment created by rivaros: Update: fixed the last problem in Doctrine/ORM/Tools/EntityGenerator.php Still has to be fixed in YAML/XML exporters - not very familiar with the syntax.
Author
Owner

@doctrinebot commented on GitHub (Mar 3, 2012):

Comment created by @beberlei:

This PR fixes the problem https://github.com/doctrine/doctrine2/pull/280

@doctrinebot commented on GitHub (Mar 3, 2012): Comment created by @beberlei: This PR fixes the problem https://github.com/doctrine/doctrine2/pull/280
Author
Owner

@doctrinebot commented on GitHub (Mar 14, 2012):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Mar 14, 2012): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Mar 14, 2012):

Issue was closed with resolution "Fixed"

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

No dependencies set.

Reference: doctrine/archived-orm#2073