Skip to content

Commit

Permalink
Fix entity class name inflection.
Browse files Browse the repository at this point in the history
Closes #12390.
  • Loading branch information
ADmad committed Jul 24, 2018
1 parent 171923f commit 49dbe09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -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());
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/test_app/TestApp/Model/Table/AddressesTable.php
@@ -0,0 +1,22 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @since 3.6.9
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace TestApp\Model\Table;

use Cake\ORM\Table;

/**
* Addresses table class
*/
class AddressesTable extends Table
{
}

0 comments on commit 49dbe09

Please sign in to comment.