In my DB I have a table page_content
with a column which is a reserved MySQL 8 word, row
.
Due to constraints mandated by my hosting system, I need to rename the column to something that isn’t a reserved word (my idea is to rename it to sort_row
).
This row
field is however, exposed by an API that my software is implementing and exposing. This API serializes the CakePHP ORM objects as JSON to expose them, which means, if I change the name of a field in my model class it will then also change accordingly in the JSON output of my API.
But I don’t want to rename the field in the API, because this would mean having to check and update every system which uses it.
The project is implemented with PHP8 and CakePHP 4.4.
I have an entity class for the table:
<?php
namespace AppModelEntity;
class PageContent extends Entity
{
protected $_accessible = [
'*' => true,
'id' => false
];
protected $_virtual = ['content'];
protected $_hidden = [
'is_visible',
'visible_from',
'visible_to',
'is_deleted',
'created',
'modified',
'created_user',
'modified_user',
];
protected function _getContent()
{
// method logic here
}
// more stuff here....
}
Is there any way I can specify an “alias” or something similar for my CakePHP model, so that while the MySQL field is called sort_row
, as far as CakePHP is concerned (in ORM queries and so on) the field is still called row
?
The documentation doesn’t really mention anything like that.
Can I use a virtual field to achieve what I need?