Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2079

Error in build entities using yml with several inversedJoinColumns

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.3.1
    • Component/s: Tools
    • Security Level: All
    • Labels:
      None
    • Environment:
      windows 7/php 5.3/apache 2.2

      Description

      Hello guys, sorry for the bad English found the error during a necessity and would like to post the solution.

      Below is an example of my yml relationamento a many to many.

      manyToMany:
      centroCustos:
      targetEntity: Album\Entity\CentroCusto
      cascade: ["persist", "merge"]
      inversedBy: unidades
      joinTable:
      name: unidade_centro_custo
      joinColumns:
      idunidade:
      referencedColumnName: idunidade
      onDelete: cascade
      inverseJoinColumns:
      idcentrocusto:
      referencedColumnName: idcentrocusto
      idpais:
      referencedColumnName: idpais
      idmundo:
      referencedColumnName: idmundo
      onDelete: cascade

      Well this example is generating this code.

      /**

      • @var \Doctrine\Common\Collections\ArrayCollection
        *
      • @ORM\ManyToMany(targetEntity="Album\Entity\CentroCusto", inversedBy="unidades", cascade= {"persist","merge"}

        )

      • @ORM\JoinTable(name="unidade_centro_custo",
      • joinColumns= { * @ORM\JoinColumn(name="idunidade", referencedColumnName="idunidade", onDelete="cascade") * }

        ,

      • inverseJoinColumns= { * @ORM\JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto") * @ORM\JoinColumn(name="idpais", referencedColumnName="idpais") * @ORM\JoinColumn(name="idmundo", referencedColumnName="idmundo", onDelete="cascade") * }
      • )
        */

      Notice that Doctrine 2 is not putting commas to separate JoinColumns.

      So looking at the source code I found the following code and put it solved my problem.

      The changes was performed in EntityGenerator.php line 1090.

      $arrJoins = array();
      foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn)

      { $arrJoins[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); }

      $lines[] = implode(",". PHP_EOL, $arrJoins);
      $lines[] = $this->spaces . ' * },';
      $lines[] = $this->spaces . ' * inverseJoinColumns={';

      $arrJoinsInverse = array();
      foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn)

      { $arrJoinsInverse[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); }

      $lines[] = implode(",". PHP_EOL, $arrJoinsInverse);
      $lines[] = $this->spaces . ' * }';
      $lines[] = $this->spaces . ' * )'; }

      I hope you understand what I'm trying to say, for you do not know if this error occurred, but if there ocorrei is one possible solution.

      Thank you.

        Activity

        André Antônio Lemos de Moraes created issue -
        André Antônio Lemos de Moraes made changes -
        Field Original Value New Value
        Description Hello guys, sorry for the bad English found the error during a necessity and would like to post the solution.

        Below is an example of my yml relationamento a many to many.

        manyToMany:
                centroCustos:
                    targetEntity: Album\Entity\CentroCusto
                    cascade: ["persist", "merge"]
                    inversedBy: unidades
                    joinTable:
                        name: unidade_centro_custo
                        joinColumns:
                            idunidade:
                                referencedColumnName: idunidade
                                onDelete: cascade
                        inverseJoinColumns:
                            idcentrocusto:
                                referencedColumnName: idcentrocusto
                            idpais:
                                referencedColumnName: idpais
                            idmundo:
                                referencedColumnName: idmundo
                                onDelete: cascade

        Well this example is generating this code.

          /**
             * @var \Doctrine\Common\Collections\ArrayCollection
             *
             * @ORM\ManyToMany(targetEntity="Album\Entity\CentroCusto", inversedBy="unidades", cascade={"persist","merge"})
             * @ORM\JoinTable(name="unidade_centro_custo",
             * joinColumns={
             * @ORM\JoinColumn(name="idunidade", referencedColumnName="idunidade", onDelete="cascade")
             * },
             * inverseJoinColumns={
             * @ORM\JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto")
             * @ORM\JoinColumn(name="idpais", referencedColumnName="idpais")
             * @ORM\JoinColumn(name="idmundo", referencedColumnName="idmundo", onDelete="cascade")
             * }
             * )
             */

        Notice that Doctrine 2 is not putting commas to separate JoinColumns.

        So looking at the source code I found the following code and put it solved my problem.

        The changes was performed in EntityGenerator.php line 1090.

                        $intNumbersJoinColumn = count($associationMapping['joinTable']['inverseJoinColumns']);
                        foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
                        
                         $strComma = "";
                         $intPositionJoinColumn = array_search($joinColumn, $associationMapping['joinTable']['inverseJoinColumns']);

                         if($intNumbersJoinColumn > 1) {
                         $strComma = ($intPositionJoinColumn < $intNumbersJoinColumn -1 ) ? "," : "" ;
                         }
                        
                            $lines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn) . $strComma ;
                        }

        I hope you understand what I'm trying to say, for you do not know if this error occurred, but if there ocorrei is one possible solution.

        Thank you.
        Hello guys, sorry for the bad English found the error during a necessity and would like to post the solution.

        Below is an example of my yml relationamento a many to many.

        manyToMany:
                centroCustos:
                    targetEntity: Album\Entity\CentroCusto
                    cascade: ["persist", "merge"]
                    inversedBy: unidades
                    joinTable:
                        name: unidade_centro_custo
                        joinColumns:
                            idunidade:
                                referencedColumnName: idunidade
                                onDelete: cascade
                        inverseJoinColumns:
                            idcentrocusto:
                                referencedColumnName: idcentrocusto
                            idpais:
                                referencedColumnName: idpais
                            idmundo:
                                referencedColumnName: idmundo
                                onDelete: cascade

        Well this example is generating this code.

          /**
             * @var \Doctrine\Common\Collections\ArrayCollection
             *
             * @ORM\ManyToMany(targetEntity="Album\Entity\CentroCusto", inversedBy="unidades", cascade={"persist","merge"})
             * @ORM\JoinTable(name="unidade_centro_custo",
             * joinColumns={
             * @ORM\JoinColumn(name="idunidade", referencedColumnName="idunidade", onDelete="cascade")
             * },
             * inverseJoinColumns={
             * @ORM\JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto")
             * @ORM\JoinColumn(name="idpais", referencedColumnName="idpais")
             * @ORM\JoinColumn(name="idmundo", referencedColumnName="idmundo", onDelete="cascade")
             * }
             * )
             */

        Notice that Doctrine 2 is not putting commas to separate JoinColumns.

        So looking at the source code I found the following code and put it solved my problem.

        The changes was performed in EntityGenerator.php line 1090.

                        $arrJoins = array();
                        foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
                        
                         $arrJoins[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
                        }
                        
                        $lines[] = implode(", ". PHP_EOL, $arrJoins); }

        I hope you understand what I'm trying to say, for you do not know if this error occurred, but if there ocorrei is one possible solution.

        Thank you.
        André Antônio Lemos de Moraes made changes -
        Description Hello guys, sorry for the bad English found the error during a necessity and would like to post the solution.

        Below is an example of my yml relationamento a many to many.

        manyToMany:
                centroCustos:
                    targetEntity: Album\Entity\CentroCusto
                    cascade: ["persist", "merge"]
                    inversedBy: unidades
                    joinTable:
                        name: unidade_centro_custo
                        joinColumns:
                            idunidade:
                                referencedColumnName: idunidade
                                onDelete: cascade
                        inverseJoinColumns:
                            idcentrocusto:
                                referencedColumnName: idcentrocusto
                            idpais:
                                referencedColumnName: idpais
                            idmundo:
                                referencedColumnName: idmundo
                                onDelete: cascade

        Well this example is generating this code.

          /**
             * @var \Doctrine\Common\Collections\ArrayCollection
             *
             * @ORM\ManyToMany(targetEntity="Album\Entity\CentroCusto", inversedBy="unidades", cascade={"persist","merge"})
             * @ORM\JoinTable(name="unidade_centro_custo",
             * joinColumns={
             * @ORM\JoinColumn(name="idunidade", referencedColumnName="idunidade", onDelete="cascade")
             * },
             * inverseJoinColumns={
             * @ORM\JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto")
             * @ORM\JoinColumn(name="idpais", referencedColumnName="idpais")
             * @ORM\JoinColumn(name="idmundo", referencedColumnName="idmundo", onDelete="cascade")
             * }
             * )
             */

        Notice that Doctrine 2 is not putting commas to separate JoinColumns.

        So looking at the source code I found the following code and put it solved my problem.

        The changes was performed in EntityGenerator.php line 1090.

                        $arrJoins = array();
                        foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
                        
                         $arrJoins[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
                        }
                        
                        $lines[] = implode(", ". PHP_EOL, $arrJoins); }

        I hope you understand what I'm trying to say, for you do not know if this error occurred, but if there ocorrei is one possible solution.

        Thank you.
        Hello guys, sorry for the bad English found the error during a necessity and would like to post the solution.

        Below is an example of my yml relationamento a many to many.

        manyToMany:
                centroCustos:
                    targetEntity: Album\Entity\CentroCusto
                    cascade: ["persist", "merge"]
                    inversedBy: unidades
                    joinTable:
                        name: unidade_centro_custo
                        joinColumns:
                            idunidade:
                                referencedColumnName: idunidade
                                onDelete: cascade
                        inverseJoinColumns:
                            idcentrocusto:
                                referencedColumnName: idcentrocusto
                            idpais:
                                referencedColumnName: idpais
                            idmundo:
                                referencedColumnName: idmundo
                                onDelete: cascade

        Well this example is generating this code.

          /**
             * @var \Doctrine\Common\Collections\ArrayCollection
             *
             * @ORM\ManyToMany(targetEntity="Album\Entity\CentroCusto", inversedBy="unidades", cascade={"persist","merge"})
             * @ORM\JoinTable(name="unidade_centro_custo",
             * joinColumns={
             * @ORM\JoinColumn(name="idunidade", referencedColumnName="idunidade", onDelete="cascade")
             * },
             * inverseJoinColumns={
             * @ORM\JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto")
             * @ORM\JoinColumn(name="idpais", referencedColumnName="idpais")
             * @ORM\JoinColumn(name="idmundo", referencedColumnName="idmundo", onDelete="cascade")
             * }
             * )
             */

        Notice that Doctrine 2 is not putting commas to separate JoinColumns.

        So looking at the source code I found the following code and put it solved my problem.

        The changes was performed in EntityGenerator.php line 1090.

          $arrJoins = array();
          foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
                        
            $arrJoins[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
                        }
                        
          $lines[] = implode(", ". PHP_EOL, $arrJoins); }

        I hope you understand what I'm trying to say, for you do not know if this error occurred, but if there ocorrei is one possible solution.

        Thank you.
        André Antônio Lemos de Moraes made changes -
        Description Hello guys, sorry for the bad English found the error during a necessity and would like to post the solution.

        Below is an example of my yml relationamento a many to many.

        manyToMany:
                centroCustos:
                    targetEntity: Album\Entity\CentroCusto
                    cascade: ["persist", "merge"]
                    inversedBy: unidades
                    joinTable:
                        name: unidade_centro_custo
                        joinColumns:
                            idunidade:
                                referencedColumnName: idunidade
                                onDelete: cascade
                        inverseJoinColumns:
                            idcentrocusto:
                                referencedColumnName: idcentrocusto
                            idpais:
                                referencedColumnName: idpais
                            idmundo:
                                referencedColumnName: idmundo
                                onDelete: cascade

        Well this example is generating this code.

          /**
             * @var \Doctrine\Common\Collections\ArrayCollection
             *
             * @ORM\ManyToMany(targetEntity="Album\Entity\CentroCusto", inversedBy="unidades", cascade={"persist","merge"})
             * @ORM\JoinTable(name="unidade_centro_custo",
             * joinColumns={
             * @ORM\JoinColumn(name="idunidade", referencedColumnName="idunidade", onDelete="cascade")
             * },
             * inverseJoinColumns={
             * @ORM\JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto")
             * @ORM\JoinColumn(name="idpais", referencedColumnName="idpais")
             * @ORM\JoinColumn(name="idmundo", referencedColumnName="idmundo", onDelete="cascade")
             * }
             * )
             */

        Notice that Doctrine 2 is not putting commas to separate JoinColumns.

        So looking at the source code I found the following code and put it solved my problem.

        The changes was performed in EntityGenerator.php line 1090.

          $arrJoins = array();
          foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
                        
            $arrJoins[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
                        }
                        
          $lines[] = implode(", ". PHP_EOL, $arrJoins); }

        I hope you understand what I'm trying to say, for you do not know if this error occurred, but if there ocorrei is one possible solution.

        Thank you.
        Hello guys, sorry for the bad English found the error during a necessity and would like to post the solution.

        Below is an example of my yml relationamento a many to many.

        manyToMany:
                centroCustos:
                    targetEntity: Album\Entity\CentroCusto
                    cascade: ["persist", "merge"]
                    inversedBy: unidades
                    joinTable:
                        name: unidade_centro_custo
                        joinColumns:
                            idunidade:
                                referencedColumnName: idunidade
                                onDelete: cascade
                        inverseJoinColumns:
                            idcentrocusto:
                                referencedColumnName: idcentrocusto
                            idpais:
                                referencedColumnName: idpais
                            idmundo:
                                referencedColumnName: idmundo
                                onDelete: cascade

        Well this example is generating this code.

          /**
             * @var \Doctrine\Common\Collections\ArrayCollection
             *
             * @ORM\ManyToMany(targetEntity="Album\Entity\CentroCusto", inversedBy="unidades", cascade={"persist","merge"})
             * @ORM\JoinTable(name="unidade_centro_custo",
             * joinColumns={
             * @ORM\JoinColumn(name="idunidade", referencedColumnName="idunidade", onDelete="cascade")
             * },
             * inverseJoinColumns={
             * @ORM\JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto")
             * @ORM\JoinColumn(name="idpais", referencedColumnName="idpais")
             * @ORM\JoinColumn(name="idmundo", referencedColumnName="idmundo", onDelete="cascade")
             * }
             * )
             */

        Notice that Doctrine 2 is not putting commas to separate JoinColumns.

        So looking at the source code I found the following code and put it solved my problem.

        The changes was performed in EntityGenerator.php line 1090.

                        $arrJoins = array();
                        foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) {
                            $arrJoins[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
                        }
                        
                        $lines[] = implode(",". PHP_EOL, $arrJoins);
                        $lines[] = $this->spaces . ' * },';
                        $lines[] = $this->spaces . ' * inverseJoinColumns={';
                        
                        $arrJoinsInverse = array();
                        foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
                        
                         $arrJoinsInverse[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
                        }
                        
                        $lines[] = implode(",". PHP_EOL, $arrJoinsInverse);
                        $lines[] = $this->spaces . ' * }';
                        $lines[] = $this->spaces . ' * )'; }

        I hope you understand what I'm trying to say, for you do not know if this error occurred, but if there ocorrei is one possible solution.

        Thank you.
        André Antônio Lemos de Moraes made changes -
        Priority Major [ 3 ] Critical [ 2 ]
        Fabio B. Silva made changes -
        Assignee Benjamin Eberlei [ beberlei ] Fabio B. Silva [ fabio.bat.silva ]
        Fabio B. Silva made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Show
        Fabio B. Silva added a comment - Fixed by : https://github.com/doctrine/doctrine2/commit/2c0feb2a46a7cf97dc2878e6214924c3ffdbce67
        Fabio B. Silva made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 2.3 [ 10185 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Fix Version/s 2.3.1 [ 10323 ]

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

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            André Antônio Lemos de Moraes
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: