[DDC-2079] Error in build entities using yml with several inversedJoinColumns Created: 15/Oct/12  Updated: 09/Nov/12  Resolved: 21/Oct/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: 2.3
Fix Version/s: 2.3.1
Security Level: All

Type: Bug Priority: Critical
Reporter: André Antônio Lemos de Moraes Assignee: Fabio B. Silva
Resolution: Fixed Votes: 0
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.



 Comments   
Comment by Fabio B. Silva [ 21/Oct/12 ]

Fixed by : https://github.com/doctrine/doctrine2/commit/2c0feb2a46a7cf97dc2878e6214924c3ffdbce67

Generated at Wed Jul 30 21:15:46 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.