Type: New Feature
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All
Environment:debian lenny, smyfony2, postgres 8.4
We are trying to create an association which referenced column is not a primary key.
The source entity mapping looks like:
<entity name="Joiz\HomeBundle\Entity\ShowInstanceTeaser" table="teaser">
<many-to-one field="showInstance" target-entity="Joiz\ShowBundle\Entity\ShowInstance">
<join-column name="show_instance_extid" referenced-column-name="extid" />
The destination entity mapping is:
<entity name="Joiz\ShowBundle\Entity\ShowInstance" table="show_instance" repository-class="Joiz\ShowBundle\Entity\ShowInstanceRepository">
<id name="id" column="id" type="integer">
<generator strategy="IDENTITY" />
<field name="extid" column="extid" type="string" unique="true" />
<!-- ... snip ... -->
Doctrine will correctly create the tables with the above mapping but the association does not seem to work.
When we try to load some data in the tables:
$showInst = new ShowInstance();
$teaser = new ShowInstanceTeaser();
This will leave the column "teaser.show_instance_extid" null.
Doing the same but using the primary key for the association will work.
In a discussion on the #doctrine-dev channel on freenode beberlei explained:
<beberlei> ah the problem is probably the CommitOrderCalculator does not know of this foreign key
<beberlei> and sorts the inserts in the wrong order
<beberlei> you cannot add foreign keys say through some mapping information in annotations or xml the like
<beberlei> you have to create them manually
<beberlei> and in this case doctrine might end up in troubles depending on the commit order
<beberlei> hibernate solves this by allowing to specifiy additional constraints that are recognized while calculating the commit order, but this is not yet in tdoctrine2. can you open up a ticket for this?