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 Bug
    • Status: Resolved
    • Priority: Major 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

        Kéri Norbert created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3 [ 10185 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13199 ] jira-feedback [ 15116 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15116 ] jira-feedback2 [ 16980 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16980 ] jira-feedback3 [ 19233 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: