Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1648

Primary Keys as Foreign Keys - still not working in Reverse Engineering in 2.1.6

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.6
    • Fix Version/s: 2.1.7, 2.2.2
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      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?

        Activity

        ross neacoders created issue -
        Hide
        Benjamin Eberlei added a comment -

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

        Show
        Benjamin Eberlei added a comment - In lib/Doctrine/ORM/Mapping/DatabaseDriver.php
        Hide
        ross neacoders added a comment -

        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.

        Show
        ross neacoders added a comment - 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.
        Hide
        ross neacoders added a comment - - edited

        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.

        Show
        ross neacoders added a comment - - edited 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.
        Hide
        ross neacoders added a comment -

        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.

        Show
        ross neacoders added a comment - 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.
        Hide
        Benjamin Eberlei added a comment -
        Show
        Benjamin Eberlei added a comment - This PR fixes the problem https://github.com/doctrine/doctrine2/pull/280
        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.1.7 [ 10198 ]
        Fix Version/s 2.2.2 [ 10195 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13436 ] jira-feedback [ 15229 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15229 ] jira-feedback2 [ 17093 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17093 ] jira-feedback3 [ 19346 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1648, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            ross neacoders
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: