Details
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.
Can you provide your changes as a patch?