Development

#3525 ([PATCH]: sfDoctrinePlugin/FormGenerator: isColumnForeignKey returns true on PrimaryKeyColumns)

You must first sign up to be able to contribute.

Ticket #3525 (closed defect: fixed)

Opened 7 months ago

Last modified 7 months ago

[PATCH]: sfDoctrinePlugin/FormGenerator: isColumnForeignKey returns true on PrimaryKeyColumns

Reported by: thomas.s Assigned to: Jonathan.Wage
Priority: major Milestone:
Component: sfDoctrinePlugin Version: 1.1.0 RC1
Keywords: form generation doctrine Cc:
Qualification: Unreviewed

Description

The function isColumnsForeignKey in the sfDoctrineFormGenerator class returns true if the column is a primary key column. Therefore the wrong model name is used for the validator of the primary key column.

Fix:

/**
    * Check if a column is a foreign key
    *
    * @param array $column 
    * @return boolean $bool
    */
    public function isColumnForeignKey($name)
    {
        if ($this->isColumnPrimaryKey($name)) {
            return false;
        }
        foreach ($this->table->getRelations() as $relation)
        {
            if ($relation['local'] == $name)
            {
                return true;
            }
        }
        return false;
    }

For my attached unit tests (PHPUnit, but you can read it like pseudo code) i extended the generator with a function to inject the model name:

public function setTable($name)
      {
        $this->table = Doctrine::getTable($name);
        $this->modelName = $name;
      }

Attachments

many-to-many-schema.yml (0.9 kB) - added by thomas.s on 05/13/08 15:38:24.
one-to-many-schema.yml (311 bytes) - added by thomas.s on 05/13/08 15:39:08.
many-to-many-fixture.yml (101 bytes) - added by thomas.s on 05/13/08 15:39:21.
one-to-many-fixture.yml (71 bytes) - added by thomas.s on 05/13/08 15:39:31.
FormGeneratorTest.php (6.1 kB) - added by thomas.s on 05/13/08 15:39:49.

Change History

05/13/08 15:38:24 changed by thomas.s

  • attachment many-to-many-schema.yml added.

05/13/08 15:39:08 changed by thomas.s

  • attachment one-to-many-schema.yml added.

05/13/08 15:39:21 changed by thomas.s

  • attachment many-to-many-fixture.yml added.

05/13/08 15:39:31 changed by thomas.s

  • attachment one-to-many-fixture.yml added.

05/13/08 15:39:49 changed by thomas.s

  • attachment FormGeneratorTest.php added.

05/13/08 15:47:04 changed by thomas.s

  • summary changed from [PATCH]: sfGuardDoctrinePlugin/FormGenerator: isColumnForeignKey returns true on PrimaryKeyColumns to [PATCH]: sfDoctrinePlugin/FormGenerator: isColumnForeignKey returns true on PrimaryKeyColumns.

05/14/08 03:46:17 changed by Jonathan.Wage

  • status changed from new to closed.
  • resolution set to fixed.

(In [8936]) fixes #3525