From df3108e61b5cea0e5d1de3d9e2182bc8e5009c92 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Fri, 12 Apr 2024 22:54:39 +0200 Subject: [PATCH 1/2] fix(Table): support for index declared with single field as string --- .../IndexesUsingSingleFieldStringTestCase.php | 27 +++++++++++++++++++ tests/run.php | 1 + 2 files changed, 28 insertions(+) create mode 100644 tests/Table/IndexesUsingSingleFieldStringTestCase.php diff --git a/tests/Table/IndexesUsingSingleFieldStringTestCase.php b/tests/Table/IndexesUsingSingleFieldStringTestCase.php new file mode 100644 index 000000000..1c4261dc8 --- /dev/null +++ b/tests/Table/IndexesUsingSingleFieldStringTestCase.php @@ -0,0 +1,27 @@ +tables = array('IndexDeclaredWithSingleFieldStringRecord'); + + parent::prepareTables(); + } + + public function testSupportIndexesUsingSingleFieldString() + { + } +} + +class IndexDeclaredWithSingleFieldStringRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('some_column_name', 'string', 255); + + $this->index('single_field_index_as_string', array( + 'fields' => 'some_column_name', + )); + } +} diff --git a/tests/run.php b/tests/run.php index d1dd2c7ee..16fe619fa 100644 --- a/tests/run.php +++ b/tests/run.php @@ -140,6 +140,7 @@ $core->addTestCase(new Doctrine_Table_TestCase()); $core->addTestCase(new Doctrine_Table_RemoveColumn_TestCase()); $core->addTestCase(new Doctrine_Table_NamedQuery_TestCase()); +$core->addTestCase(new Doctrine_Table_IndexesUsingSingleFieldString_TestCase()); $core->addTestCase(new Doctrine_UnitOfWork_TestCase()); $core->addTestCase(new Doctrine_Collection_TestCase()); $core->addTestCase(new Doctrine_Collection_Snapshot_TestCase()); From a7cfab209c88f6dfdc35cfd19b46882463ad6bd0 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Fri, 12 Apr 2024 23:18:23 +0200 Subject: [PATCH 2/2] fixup! fix(Table): support for index declared with single field as string --- lib/Doctrine/Table.php | 4 +++- tests/Table/IndexesUsingSingleFieldStringTestCase.php | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index faac80574..535d57ccf 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -880,7 +880,9 @@ public function addCheckConstraint($definition, $name) public function addIndex($index, array $definition) { if (isset($definition['fields'])) { - foreach ((array) $definition['fields'] as $key => $field) { + $definition['fields'] = (array) $definition['fields']; + + foreach ($definition['fields'] as $key => $field) { if (is_numeric($key)) { $definition['fields'][$key] = $this->getColumnName($field); } else { diff --git a/tests/Table/IndexesUsingSingleFieldStringTestCase.php b/tests/Table/IndexesUsingSingleFieldStringTestCase.php index 1c4261dc8..21300f41a 100644 --- a/tests/Table/IndexesUsingSingleFieldStringTestCase.php +++ b/tests/Table/IndexesUsingSingleFieldStringTestCase.php @@ -2,12 +2,7 @@ class Doctrine_Table_IndexesUsingSingleFieldString_TestCase extends Doctrine_UnitTestCase { - public function prepareTables() - { - $this->tables = array('IndexDeclaredWithSingleFieldStringRecord'); - - parent::prepareTables(); - } + protected $tables = array('IndexDeclaredWithSingleFieldStringRecord'); public function testSupportIndexesUsingSingleFieldString() {