Problems / Motivations
Currently, if we want to have an entity with a field 'title', it is very difficult to do in practice (not technically) because it will create potential naming conflict if another modules require the machine name 'title' on its own entity type. The current solution is to prefix our field by the module's namespace, which is annoying and not really readable, we can improve this.
Each field instance is stored in a standardized table which name is field_data_{$field_name}
. The partitioning is vertical due to the entity_type
column. The separation of data recorded for an entity rather than another entity is done through this column. For this reason if we want to have a different $field_name in our custom entity this will be not possible: it will share the same table and the same settings.
Proposed resolution
Instead of partitioning vertically our data, we could partition it horizontally, creating a table by entity type instead of by field name.
The resolution involves the moving of the entity_type
column out of the table, and creates a new table for each entities using this field. The new name of table data would be then field_data_{$entity_type}_{$field_name}
for instance.
This would allow the creation of a 'title' field which would contain 255 characters for an entity type of node, and restricted to 64 characters for an entity type of user for instance. This is a use case among many other that I encounter in some modules i'm currently developing.