Skip to content
This repository
Browse code

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

  • Loading branch information...
commit e65d732d2d9f3d4535975e9955c147860ab8b31c 1 parent 28dfbde
Jérémie Augustin jaugustin authored
2  lib/generator/sfPropelFormGenerator.class.php
@@ -164,7 +164,7 @@ public function getManyToManyTables()
164 164 $middleTables[$middleTable->getClassname()] = $middleTable;
165 165 $tables[] = array(
166 166 'middleTable' => $middleTable,
167   - 'relatedGetter' => $foreignTable->getPhpname() == $relation->getName() ? 'get' . $middleTable->getPhpname() . 's' : 'get' . $relation->getPluralName(),
  167 + 'relatedGetter' => $foreignTable->getPhpname() == $relation->getName() ? 'get' . $middleTable->getPhpname() . 's' : 'get' . $relations[$middleTable->getClassname()]->getPluralName(),
168 168 'relatedTable' => $foreignTable,
169 169 'column' => reset($columns),
170 170 'relatedColumn' => reset($relatedColumns),
17 test/functional/fixtures/config/schema.xml
@@ -241,4 +241,21 @@
241 241 <column name="name" type="varchar" size="255" />
242 242 <column name="useless" type="varchar" size="255" />
243 243 </table>
  244 +
  245 + <table name="many">
  246 + <column name="id" type="integer" required="true" primaryKey="true" autoincrement="true" />
  247 + <column name="name" type="varchar" size="255" />
  248 + <column name="useless" type="varchar" size="255" />
  249 + </table>
  250 +
  251 + <table name="too_many" isCrossRef="true">
  252 + <column name="manyfk_id" type="integer" primaryKey="true" />
  253 + <column name="manyfk_cross_id" type="integer" primaryKey="true" />
  254 + <foreign-key foreignTable="many">
  255 + <reference local="manyfk_id" foreign="id" />
  256 + </foreign-key>
  257 + <foreign-key foreignTable="many">
  258 + <reference local="manyfk_cross_id" foreign="id" />
  259 + </foreign-key>
  260 + </table>
244 261 </database>
17 test/functional/formTest.php
@@ -311,3 +311,20 @@
311 311
312 312 $form = new SellerForm();
313 313 $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');
  314 +
  315 +$many = new Many();
  316 +$many2 = new Many();
  317 +$tooMany = new TooMany();
  318 +$tooMany->setManyRelatedByManyfkCrossId($many);
  319 +$tooMany->setManyRelatedByManyfkId($many2);
  320 +$many->save();
  321 +$form = new ManyForm($many);
  322 +$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');
  323 +
  324 +try {
  325 + // PHP Fatal if it fail
  326 + $form->updateDefaultsFromObject();
  327 + $b->test()->pass('The many to many generated form update opject normaly');
  328 +} catch (Exception $e) {
  329 + $b->test()->fail('There is an issue with the many to many generated form');
  330 +}

0 comments on commit e65d732

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