Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-1497

Orm:generate-entities generates incorrect code when it has multiple relations with the same entity

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.2
    • Fix Version/s: 2.3
    • Component/s: Tools
    • Security Level: All
    • Labels:
      None
    • Environment:
      ArchLinux, PHP 5.3.8

      Description

      Using the same entities, as in the cookbook, when you generate the entities, the add* methods on User, or generally, on the inverse for many type relations are incorrect, and overwrite each other, so you end up with only one add method, that is incorrectly named.

      Rework\Model\User:
          type: entity
          table: user
          id:
              id:
                  type: integer
                  generator:
                      strategy: AUTO
          fields:
              name:
                  type: string
          oneToMany:
              reportedBugs:
                  targetEntity: Bug
                  mappedBy: reporter
              assignedBugs:
                  targetEntity: Bug
                  mappedBy: engineer
      
      Rework\Model\Bug:
          type: entity
          table: bug
          id:
              id:
                  type: integer
                  generator:
                      strategy: AUTO
          fields:
              name:
                  type: string
          manyToOne:
              reporter:
                  targetEntity: User
                  inversedBy: reportedBugs
              engineer:
                  targetEntity: User
                  inversedBy: assignedBugs
      
      The generated method on User.php
          /**
           * Add reportedBugs
           *
           * @param Rework\Model\Bug $reportedBugs
           */
          public function addBug(\Rework\Model\Bug $reportedBugs)
          {
              $this->reportedBugs[] = $reportedBugs;
          }
      

      What I expected:
      The method should be named addReportedBugs, eg. it should be named after the relation, and not the entity's classname.
      There should also be two add* methods, instead there is only one.

        Activity

        wishcow Kéri Norbert created issue -
        Hide
        venimus venimus added a comment -

        I also reproduce that with a manyToMany relations

        The misbehavior I found to be in the EntityGenerator.php on lines 706-712

         
                if ($type == "add") {
                    $addMethod = explode("\\", $typeHint);
                    $addMethod = end($addMethod);
                    $methodName = $type . $addMethod;
                } else {
                    $methodName = $type . Inflector::classify($fieldName);
                }
        

        the whole block should be simply

         $methodName = $type . Inflector::classify($fieldName); 
        Show
        venimus venimus added a comment - I also reproduce that with a manyToMany relations The misbehavior I found to be in the EntityGenerator.php on lines 706-712 if ($type == "add" ) { $addMethod = explode( "\\" , $typeHint); $addMethod = end($addMethod); $methodName = $type . $addMethod; } else { $methodName = $type . Inflector::classify($fieldName); } the whole block should be simply $methodName = $type . Inflector::classify($fieldName);
        Hide
        schyzophrenic Schyzophrenic added a comment -

        I have also reproduced the very same issue on Doctrine 2.1.4 on a Win7 environment (using Symfony2, but it is not really relevant here).
        While waiting for a fix, I will use the provided workaround.

        Show
        schyzophrenic Schyzophrenic added a comment - I have also reproduced the very same issue on Doctrine 2.1.4 on a Win7 environment (using Symfony2, but it is not really relevant here). While waiting for a fix, I will use the provided workaround.
        Hide
        beberlei Benjamin Eberlei added a comment -

        Fixed but merged only into master, since this is also a BC break.

        Show
        beberlei Benjamin Eberlei added a comment - Fixed but merged only into master, since this is also a BC break.
        beberlei Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3 [ 10185 ]
        Resolution Fixed [ 1 ]
        beberlei Benjamin Eberlei made changes -
        Workflow jira [ 13199 ] jira-feedback [ 15116 ]
        beberlei Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15116 ] jira-feedback2 [ 16980 ]
        beberlei Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16980 ] jira-feedback3 [ 19233 ]

        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={expand=changesets[0:20].revisions[0:29],reviews, query=DDC-1497}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            wishcow Kéri Norbert
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: