diff --git a/lib/Doctrine.php b/lib/Doctrine.php index 854075759..c450c1747 100644 --- a/lib/Doctrine.php +++ b/lib/Doctrine.php @@ -191,6 +191,7 @@ final class Doctrine const ATTR_DEFAULT_PARAM_NAMESPACE = 156; const ATTR_QUERY_CACHE = 157; const ATTR_QUERY_CACHE_LIFESPAN = 158; + const ATTR_AUTOLOAD_TABLE_CLASSES = 160; /** * LIMIT CONSTANTS diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php index 5cb14c411..f7c9b7213 100644 --- a/lib/Doctrine/Configurable.php +++ b/lib/Doctrine/Configurable.php @@ -124,6 +124,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable case Doctrine::ATTR_RECORD_LISTENER: case Doctrine::ATTR_THROW_EXCEPTIONS: case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: + case Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES: break; case Doctrine::ATTR_SEQCOL_NAME: diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index dd120028d..2b837daf6 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -237,7 +237,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun if ($this->isConnected) { try { return $this->dbh->getAttribute($attribute); - } catch(Exception $e) { + } catch (Exception $e) { throw new Doctrine_Connection_Exception('Attribute ' . $attribute . ' not found.'); } } else { @@ -1014,7 +1014,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } $class = $name . 'Table'; - if (class_exists($class) && in_array('Doctrine_Table', class_parents($class))) { + if (class_exists($class, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) && + in_array('Doctrine_Table', class_parents($class))) { $table = new $class($name, $this, true); } else { $table = new Doctrine_Table($name, $this, true); diff --git a/lib/Doctrine/Formatter.php b/lib/Doctrine/Formatter.php index 7691cce17..be80d7189 100644 --- a/lib/Doctrine/Formatter.php +++ b/lib/Doctrine/Formatter.php @@ -240,6 +240,6 @@ class Doctrine_Formatter extends Doctrine_Connection_Module public function getTableName($table) { return sprintf($this->conn->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT), - preg_replace('/[^a-z0-9_\$]/i', '_', $table)); + $table); } } diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 30d52420a..b07a0c419 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -109,6 +109,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL, Doctrine::ATTR_DECIMAL_PLACES => 2, Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine', + Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES => true, ); foreach ($attributes as $attribute => $value) { $old = $this->getAttribute($attribute); diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 6c5950936..70dfa54ea 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Hydrate'); + /** * Doctrine_Query_Abstract * diff --git a/tests/Ticket/626CTestCase.php b/tests/Ticket/626CTestCase.php new file mode 100644 index 000000000..64f790a8c --- /dev/null +++ b/tests/Ticket/626CTestCase.php @@ -0,0 +1,85 @@ + + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ + +class Doctrine_Ticket_626C_TestCase extends Doctrine_UnitTestCase +{ + public function prepareData() + { } + + public function prepareTables() + { + $this->tables = array('T626C_Student1', 'T626C_Student2'); + parent::prepareTables(); + } + + protected function newStudent($cls, $id, $name) + { + $u = new $cls; + $u->id = $id; + $u->name = $name; + $u->save(); + return $u; + } + + public function testFieldNames() + { + $student1 = $this->newStudent('T626C_Student1', '07090002', 'First Student'); + + try { + $students = Doctrine_Query::create() + ->from('T626C_Student1 s INDEXBY s.id') + ->execute(array(), Doctrine::FETCH_ARRAY); + $this->pass(); + } catch (Exception $e) { + $this->fail($e->__toString()); + } + } + + public function testColNames() + { + $student1 = $this->newStudent('T626C_Student2', '07090002', 'First Student'); + + try { + $students = Doctrine_Query::create() + ->from('T626C_Student2 s INDEXBY s.id') + ->execute(array(), Doctrine::FETCH_ARRAY); + $this->pass(); + } catch (Exception $e) { + $this->fail($e->__toString()); + } + } +} + + +class T626C_Student1 extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->setTableName('T626C_Student_record_1'); + + $this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); + $this->hasColumn('s_name as name', 'varchar', 50, array ()); + } +} + +class T626C_Student2 extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->setTableName('T626C_Student_record_2'); + + $this->hasColumn('id', 'varchar', 30, array ( 'primary' => true,)); + $this->hasColumn('name', 'varchar', 50, array ()); + } +} \ No newline at end of file diff --git a/tests/run.php b/tests/run.php index 22e3d6a30..5bebfec4f 100644 --- a/tests/run.php +++ b/tests/run.php @@ -18,6 +18,7 @@ $tickets->addTestCase(new Doctrine_Ticket_587_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_576_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_583_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_626B_TestCase()); +$tickets->addTestCase(new Doctrine_Ticket_626C_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_642_TestCase()); //If you write a ticket testcase add it here like shown above! $test->addTestCase($tickets);