Doctrine 1
  1. Doctrine 1
  2. DC-522

Can not use charset and collate in a table basis when using global charset and collate in Doctrine_Manager

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.2.2
    • Component/s: Record
    • Labels:
      None
    • Environment:
      Wamp 2.0, Windows XP PS2.

      Description

      Can not use charset and collate in a table basis when using global charset and collate in Doctrine_Manager.

      When using + symfony:

      ProjectConfiguration.class.php
      public function configureDoctrine(Doctrine_Manager $manager)
        {
          $manager->setCharset('utf8');
          $manager->setCollate('utf8_bin');
        }
      
      

      And some schema like,

      schema-page.yml
      
      PageIndex:
        tableName:                           t_page_index
        columns:
          id:                                { type: integer  , length: 20 , primary: true    , autoincrement: true                                                  }
          title:                             { type: string   , length: 200                   , notnull: true                                                        }
        options:
          collate:                           utf8_general_ci
          
      
      

      When generating the database, the table will have as collate utf8_bin, not being possible overwriting it at a table level.

      This is because:

      Table.class.php
      public function __construct($name, Doctrine_Connection $conn, $initDefinition = false)
          {
              $this->_conn = $conn;
              $this->_options['name'] = $name;
              
              $this->setParent($this->_conn);           
              $this->_conn->addTable($this);
              
              $this->_parser = new Doctrine_Relation_Parser($this);
              
              if ($initDefinition) {
                  $this->record = $this->initDefinition();
      
                  $this->initIdentifier();
      
                  $this->record->setUp();
      
                  // if tree, set up tree
                  if ($this->isTree()) {
                      $this->getTree()->setUp();
                  }
              } else {
                  if ( ! isset($this->_options['tableName'])) {
                      $this->setTableName(Doctrine_Inflector::tableize($this->_options['name']));
                  }
              }
              
              $this->_filters[]  = new Doctrine_Record_Filter_Standard();
              $this->_repository = new Doctrine_Table_Repository($this);
      
              if ($charset = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET)) {
                  $this->_options['charset'] = $charset;
              }
              if ($collate = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_COLLATE)) {
                  $this->_options['collate'] = $collate;
              }
      
              $this->construct();
          }
      

      Here the charset and the collate are overwritten (in the last lines of the method) by the global values.

      A fix could be something like:

      Table.class.php
      public function __construct($name, Doctrine_Connection $conn, $initDefinition = false)
          {
              $this->_conn = $conn;
              $this->_options['name'] = $name;
              
              $this->setParent($this->_conn);           
              $this->_conn->addTable($this);
              
              $this->_parser = new Doctrine_Relation_Parser($this);
              
      
              if ($charset = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET)) {
                  $this->_options['charset'] = $charset;
              }
              if ($collate = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_COLLATE)) {
                  $this->_options['collate'] = $collate;
              }
      
              if ($initDefinition) {
                  $this->record = $this->initDefinition();
      
                  $this->initIdentifier();
      
                  $this->record->setUp();
      
                  // if tree, set up tree
                  if ($this->isTree()) {
                      $this->getTree()->setUp();
                  }
              } else {
                  if ( ! isset($this->_options['tableName'])) {
                      $this->setTableName(Doctrine_Inflector::tableize($this->_options['name']));
                  }
              }
              
              $this->_filters[]  = new Doctrine_Record_Filter_Standard();
              $this->_repository = new Doctrine_Table_Repository($this);
      
              
      
              $this->construct();
          }
      

      Now the initDefinition method is called after the setup of the global charset and collate. Then if found a collate option in the table then that collate will be used.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        Can you provide your changes as a patch?

        Show
        Jonathan H. Wage added a comment - Can you provide your changes as a patch?
        Hide
        Jonathan Nieto added a comment -

        Patch done!.

        Show
        Jonathan Nieto added a comment - Patch done!.
        Hide
        Jonathan H. Wage added a comment -

        Thanks again for another issue and patch

        Show
        Jonathan H. Wage added a comment - Thanks again for another issue and patch

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Jonathan Nieto
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: