Development

#3500 ([PATCH]: sfDoctrinePlugin form generator has trouble with setting defaults in many-to-many relations)

You must first sign up to be able to contribute.

Ticket #3500 (new defect)

Opened 4 days ago

Last modified 4 days ago

[PATCH]: sfDoctrinePlugin form generator has trouble with setting defaults in many-to-many relations

Reported by: thomas.s Assigned to: chtito
Priority: minor Milestone:
Component: sfDoctrinePlugin Version: 1.1.0 RC1
Keywords: doctrine many-to-many Cc:
Qualification: Unreviewed

Description

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);
    }

Attachments

updateDefaultsFromObject.diff (0.9 kB) - added by thomas.s on 05/08/08 19:35:41.
updateDefaultsFromObject and getManyToManyRelations

Change History

05/08/08 19:35:41 changed by thomas.s

  • attachment updateDefaultsFromObject.diff added.

updateDefaultsFromObject and getManyToManyRelations

05/08/08 19:53:18 changed by thomas.s

I shortened the business_desired_assignment_country_list to assignment_country_list, in my schema and in all forms it is business_desired_assignment_country_list, thats not a typo.