Permalink
Browse files

Merge pull request #136 from jaugustin/fix-135-m2m-same-table

fix many to many with isCrossRef=true on same table issue, close #135
  • Loading branch information...
2 parents 28dfbde + e65d732 commit 1c91492ccd19fd2a161ed3a0bfd362d43608f10b @willdurand willdurand committed Apr 10, 2012
@@ -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),
@@ -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>
@@ -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 1c91492

Please sign in to comment.