Camel Cased Table names and columns


#1

Hi,

I’m Loving CakePHP, congrats to everyone envolved in its development.

I’ doing a project with cakephp which has 2 parts:
1- A frontend for the user to interact.
2- A backend which automatically collects data from equipments.

The frontend is beeing build using cakephp’s namming convention and it’s almost done. But Now I have to link my items table that belongsTo a table created by the backend application.
The problem is that the backend application does not use cakephp’s naming convention and therefore has camelcased names for tables and columns.

I tryied in items controller:

$this->belongsTo(‘Tags’,[
‘className’ => ‘TagTable’,
‘foreignKey’ => ‘TagIdx’,
‘propertyName’ => ‘tag’
]);
The result was :
Cannot describe tag_table. It has 0 columns

and using double quotes
$this->belongsTo(‘Tags’,[
‘className’ => ‘“TagTable”’,
‘foreignKey’ => ‘TagIdx’,
‘propertyName’ => ‘tag’
]);
Cannot describe “tag_table”. It has 0 columns

I tried to find anything related in the cookbook despite it says that the naming conventions is not mandatory and that you can define which classes and fields to use as I tried, I cant find anything related to camelCased issues.

I cant change the the tables name because I don’t have access to the backend application’s source code.

I hope there’s a way,
Tanks in advance


#2

If I understand correctly, the table “Tags” is not managed by your cakephp-app, but managed by your backend-system.

Using cakephp3, you can simply create a table-class, define the (non-cake-convention-)table-name as the db-table to be used and your relation should resolve well.

See this link for how to set the name of the database table that a cakephp-table-class is using (The method needs to be called inside the initialize()-function, if I reminder right).