Form generator fails setting the default values on many-to-many relations.
In sfDoctrineFormGeneratedTemplate, line 61:
<?php foreach ($this->getManyToManyRelations() as $relation): ?>
if (isset($this->widgetSchema['<?php echo $this->underscore($relation['refTable']->getOption('name')) ?>_list']))
{
$values = array();
foreach ($this->object-><?php echo $relation['alias']; ?> as $obj)
{
$values[] = $obj-><?php echo $relation->getForeignFieldName(); ?>;
}
$this->setDefault('<?php echo $this->underscore($relation['refTable']->getOption('name')) ?>_list', $values);
}
<?php endforeach; ?>
Generated form contains:
if (isset($this->widgetSchema['assignment_country_list']))
{
$values = array();
foreach ($this->object->Countries as $obj)
{
$values[] = $obj->country_id;
}
$this->setDefault('assignment_country_list', $values);
}
n:m between Assignment and Country (refTable AssignmentCountry). $this->object is Assignment. A Assignment has Countries, but these Countries have the primary key "id", the country_id is the key of the refTable.
The following gets the correct results (see attached patch):
if (isset($this->widgetSchema['business_desired_assignment_country_list']))
{
$values = array();
foreach ($this->object->Countries as $obj)
{
$values[] = current($obj->identifier());
}
$this->setDefault('business_desired_assignment_country_list', $values);
}