Skip to content
Browse files

fix many to many with isCrossRef=true on same table issue, close #135

  • Loading branch information...
1 parent 28dfbde commit e65d732d2d9f3d4535975e9955c147860ab8b31c @jaugustin committed Apr 11, 2012
View
2 lib/generator/sfPropelFormGenerator.class.php
@@ -164,7 +164,7 @@ public function getManyToManyTables()
$middleTables[$middleTable->getClassname()] = $middleTable;
$tables[] = array(
'middleTable' => $middleTable,
- 'relatedGetter' => $foreignTable->getPhpname() == $relation->getName() ? 'get' . $middleTable->getPhpname() . 's' : 'get' . $relation->getPluralName(),
+ 'relatedGetter' => $foreignTable->getPhpname() == $relation->getName() ? 'get' . $middleTable->getPhpname() . 's' : 'get' . $relations[$middleTable->getClassname()]->getPluralName(),
'relatedTable' => $foreignTable,
'column' => reset($columns),
'relatedColumn' => reset($relatedColumns),
View
17 test/functional/fixtures/config/schema.xml
@@ -241,4 +241,21 @@
<column name="name" type="varchar" size="255" />
<column name="useless" type="varchar" size="255" />
</table>
+
+ <table name="many">
+ <column name="id" type="integer" required="true" primaryKey="true" autoincrement="true" />
+ <column name="name" type="varchar" size="255" />
+ <column name="useless" type="varchar" size="255" />
+ </table>
+
+ <table name="too_many" isCrossRef="true">
+ <column name="manyfk_id" type="integer" primaryKey="true" />
+ <column name="manyfk_cross_id" type="integer" primaryKey="true" />
+ <foreign-key foreignTable="many">
+ <reference local="manyfk_id" foreign="id" />
+ </foreign-key>
+ <foreign-key foreignTable="many">
+ <reference local="manyfk_cross_id" foreign="id" />
+ </foreign-key>
+ </table>
</database>
View
17 test/functional/formTest.php
@@ -311,3 +311,20 @@
$form = new SellerForm();
$b->test()->isa_ok($form->getWidget('extra_seller_list'), 'sfWidgetFormPropelChoice', 'The Seller form should have a sfWidgetFormPropelChoice of extras when there is a isCrossRef on a middle table');
+
+$many = new Many();
+$many2 = new Many();
+$tooMany = new TooMany();
+$tooMany->setManyRelatedByManyfkCrossId($many);
+$tooMany->setManyRelatedByManyfkId($many2);
+$many->save();
+$form = new ManyForm($many);
+$b->test()->isa_ok($form->getWidget('too_many_list'), 'sfWidgetFormPropelChoice', 'The Many form should have a sfWidgetFormPropelChoice of Many when there is a isCrossRef on a middle table');
+
+try {
+ // PHP Fatal if it fail
+ $form->updateDefaultsFromObject();
+ $b->test()->pass('The many to many generated form update opject normaly');
+} catch (Exception $e) {
+ $b->test()->fail('There is an issue with the many to many generated form');
+}

0 comments on commit e65d732

Please sign in to comment.
Something went wrong with that request. Please try again.