From 49dbe09b95f61b258b58207911eda054874596d5 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 24 Jul 2018 18:14:34 +0530 Subject: [PATCH] Fix entity class name inflection. Closes #12390. --- src/ORM/Table.php | 2 +- tests/TestCase/ORM/TableTest.php | 7 ++++++ .../TestApp/Model/Table/AddressesTable.php | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/test_app/TestApp/Model/Table/AddressesTable.php diff --git a/src/ORM/Table.php b/src/ORM/Table.php index 196e669b5c2..483b2cea174 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -773,7 +773,7 @@ public function getEntityClass() return $this->_entityClass = $default; } - $alias = Inflector::classify(Inflector::singularize(Inflector::underscore(substr(array_pop($parts), 0, -5)))); + $alias = Inflector::classify(Inflector::underscore(substr(array_pop($parts), 0, -5))); $name = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $alias; if (!class_exists($name)) { return $this->_entityClass = $default; diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index a64283a5054..84f3189324e 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -1519,6 +1519,13 @@ class_alias($class, 'TestApp\Model\Entity\CustomCookie'); $table = $this->getTableLocator()->get('CustomCookies'); $this->assertEquals('TestApp\Model\Entity\CustomCookie', $table->getEntityClass()); + + if (!class_exists('TestApp\Model\Entity\Address')) { + class_alias($class, 'TestApp\Model\Entity\Address'); + } + + $table = $this->getTableLocator()->get('Addresses'); + $this->assertEquals('TestApp\Model\Entity\Address', $table->getEntityClass()); } /** diff --git a/tests/test_app/TestApp/Model/Table/AddressesTable.php b/tests/test_app/TestApp/Model/Table/AddressesTable.php new file mode 100644 index 00000000000..3f6869b9ee9 --- /dev/null +++ b/tests/test_app/TestApp/Model/Table/AddressesTable.php @@ -0,0 +1,22 @@ +