I have a legacy (not written to Cake naming conventions) database on a CakePHP 3.5.13 application.
One of the database tables is named article_95
.
When I attempted to bake the application it's showing the entity name as Article95
. It's then producing loads of error messages saying:
Table 'article95' doesn't exist
So I've read CakePHP error: cake bake is using the wrong table name and How to use table name different then in database in cake php 3 and decided to do it manually using setTable()
.
So I have created src/Model/Table/Article95Table.php
with the following code in it:
namespace App\Model\Table;
use Cake\ORM\Table;
class Article95Table extends Table
{
public function initialize(array $config)
{
$this->setTable('article_95');
}
}
But it won't seem to recgonise this. In a controller I've created a testing method and done the following:
Cache::clear(false);
$Article95 = TableRegistry::get('Article95');
debug($Article95->find()->list());
But it's coming up with:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'article95' doesn't exist
It's as if it's not reading the setTable()
method.
I've used the Cache::clear(false)
to ensure it's not being cached and have inspected the tmp/cache
directory for any suspect files - nothing relevant in there.
Any ideas?
Equally if I change my debug()
statement to just debug($Article95)
I get the following, with the wrong table name:
object(Cake\ORM\Table) {
'registryAlias' => 'Article95',
'table' => 'article95',
'alias' => 'Article95',
'entityClass' => '\Cake\ORM\Entity',
'associations' => [],
'behaviors' => [],
'defaultConnection' => 'default',
'connectionName' => 'default'
}
Incidentally, if I put a non-existent class/entity name in TableRegistry::get()
- for example TableRegistry::get('dsfdsfdsfsd');
it won't produce an error message but will show the object above with the non-existent table name. Surely this is also wrong?
\Cake\ORM\Table
, because the concrete table classArticle95Table
could not be found. The same thing that happens fordsfdsfdsfsd
. – ndmArticle95Table.php
inside the appropriate directory! It's working for other models I've created butbake
seems to have been happy to work with their naming scheme. – Andy