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

Closed
doctrinebot opened this Issue Feb 12, 2012 · 7 comments

2 participants

@doctrinebot

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?

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

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

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 fieldassociations and mappingassociations 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 staff - it is common for annotation/yaml/xml, e.x. when i generated xml for entity, it also does not contain tag.

@doctrinebot

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

Comment created by @beberlei:

This PR fixes the problem #280

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1.7 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment