Skip to content


DDC-2079: Error in build entities using yml with several inversedJoinColumns #2761

doctrinebot opened this Issue · 2 comments

1 participant


Jira issue originally created by user coisa2004:

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.

targetEntity: Album\Entity\CentroCusto
cascade: ["persist", "merge"]
inversedBy: unidades
name: unidadecentrocusto
referencedColumnName: idunidade
onDelete: cascade
referencedColumnName: idcentrocusto
referencedColumnName: idpais
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="unidadecentrocusto",
* 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.


Comment created by @FabioBatSilva:

Fixed by : 2c0feb2


Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.3.1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.