Code snippets for symfony 1.x


Refine Tags

Snippets tagged "propel dbdesigner"

Doctrine import from propel improvement

Sometimes a table needs to have non-autoincremented primary keys (for example, to be able to import data from other sources keeping the same id's for objects).

I use the following procedure:

  1. DBDesigner -> Propel schema (config/schema.xml) through DBDesigner2Propel

  2. Generate Doctrine schema (config/doctrine/schema.yml) through symfony doctrine-import.

The problem is that the resulting schema.yml no longer includes information about the primary keys, so doctrine-insert-sql and doctrine-build-model will create an id field as autoincremented primary key.

The solution is a small patch which doesn't change the default behaviour. Look at sfDoctrineSchemaPropelLoader.class.php around the line 52 and modify a few lines in the code to be as the following:

// columns
foreach ($propelDatabaseSchema->getChildren($tableDesc) as $col_name => $columnDescription)
  $docCol = new sfDoctrineColumnSchema($col_name, $columnDescription, true);
  if($col_name == 'id') {
          if($docCol->getColumnInfo()->get('autoIncrement') === true) {
                  // We skip integer auto-increment primary keys, but we keep the rest

There is a bug in sfDoctrineColumnSchema.class.php which should be fixed too. The problem is that it is intersecting with the non-translated constraints instead the ones already translated from propel.

The fix is easy:

Original line:

    if ($constraints = array_intersect_key($columnDescription, array_flip(self::$allowedConstraints)))

Change to this:

    // Change to this:
    if ($constraints = array_intersect_key($this->columnInfo->getAll(), array_flip(self::$allowedConstraints)))
by Fernando Monera on 2007-08-07, tagged autoincrement  convert  dbdesigner  doctrine  import  primary  propel