Doctrine 1
  1. Doctrine 1
  2. DC-717

Default value for columns is generated wrong. THe default value becomes the result value in the schema files.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.2.2
    • Component/s: Schema Files
    • Labels:
      None
    • Environment:
      Apache 2.2, PostgresSQL 8.4, Windows XP

      Description

      When generating models from db with doctrine 1.2.2, default with functions in database get evaluated and the value goes to the generated schema files thus cousing error on insert/update.

      Example:
      Table:
      CREATE TABLE Usuario (
      id SERIAL NOT NULL,
      apelido CHARACTER VARYING(50) NOT NULL,
      email CHARACTER VARYING(255) NOT NULL,
      dtRegistro TIMESTAMP DEFAULT 'now()' NOT NULL,
      idUsuarioSituacao INTEGER,
      senha CHARACTER(32),
      CONSTRAINT PK_Usuario PRIMARY KEY (id),
      CONSTRAINT TUC_Usuario_1 UNIQUE (email)
      )

      Code to generate files:
      $dManager = Doctrine_Manager::getInstance();
      $dManager->setAttribute(Doctrine::ATTR_MODEL_LOADING,Doctrine::MODEL_LOADING_CONSERVATIVE);
      $dManager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);

      $dManager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_NONE);
      $dManager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_NONE);
      $dManager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
      $dManager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
      $dManager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS);

      Doctrine_Core::generateModelsFromDb('c:\temp', array('dbcon'), array('generateTableClasses' => true, 'classPrefix' => 'D'));

      Resulting file:
      abstract class DBaseUsuario extends Doctrine_Record
      {
      public function setTableDefinition()

      { $this->setTableName('usuario'); $this->hasColumn('id', 'integer', 4, array( 'type' => 'integer', 'length' => 4, 'fixed' => false, 'unsigned' => false, 'primary' => true, 'sequence' => 'usuario_id', )); $this->hasColumn('apelido', 'string', null, array( 'type' => 'string', 'fixed' => false, 'unsigned' => false, 'notnull' => true, 'primary' => false, )); $this->hasColumn('email', 'string', null, array( 'type' => 'string', 'fixed' => false, 'unsigned' => false, 'notnull' => true, 'primary' => false, )); $this->hasColumn('dtregistro', 'timestamp', null, array( 'type' => 'timestamp', 'fixed' => false, 'unsigned' => false, 'notnull' => true, 'default' => '\'2010-06-04 11:10:12.078\'::timestamp without time zone', 'primary' => false, )); $this->hasColumn('idusuariosituacao', 'integer', 4, array( 'type' => 'integer', 'length' => 4, 'fixed' => false, 'unsigned' => false, 'notnull' => false, 'primary' => false, )); $this->hasColumn('senha', 'string', null, array( 'type' => 'string', 'fixed' => true, 'unsigned' => false, 'notnull' => false, 'primary' => false, )); }

      }

      The function now() for default value gets replaced by 'default' => '\'2010-06-04 11:10:12.078\'::timestamp without time zone',

        Activity

        Hide
        angelo ayres camargo added a comment -

        as of now i dont know if this is a error from case modeling tool or doctrine, will close and do further testing.

        Show
        angelo ayres camargo added a comment - as of now i dont know if this is a error from case modeling tool or doctrine, will close and do further testing.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            angelo ayres camargo
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: