I’m developping an application with CakePHP and I’m experiencing some problems with my DB.
The problem is that I have some tables with these kind of columns: sex (male/female), kind(image, video, text, song, link,…), …
There is many way to solve this problem:
- Creating linked tables listing sexes, kind of media, … but I already have many tables so I don’t want to overkill my DB.
- Chose the data type ENUM for the columns but CakePHP don’t like it.
- Use 1,2,3,… as an index for these columns and map an array in PHP for each columns (not a good idea in my opinion, where to instantiate these aray ?, hard to know the real value of an item in the db, …).
- Use the real, full textual value of the column for each items in the table but it’s redundant so loss of memory.
Personally, I think that the 4th possibility is the best but I would like to have other opinions or ideas to solve this problem.
Thanks in advance!
EDIT: I’m thinking of an other way to solve it.
If I make a table for each list, I’ll have many tables with just a few item and it’s a problem for the maintenance of the DB.
But if I make a table called for ex. “app_contants” which have an id, a name and a category (ex.: ‘1’, ‘female’, ‘user_sex’). All tables which need a list item, will refer on this table and if I want a specific list of this table, I just have to make “$this->AppContants->find(‘list’, array(‘conditions’ => array(‘category’, ‘user_sex’)));”
What do you think about this ?
there are many solutions out there:
the array datasource for example
But I prefer working with class constants and static methods representing the enums:
http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/
A few months ago I even added Enum support in my baking templates.
Makes them work out of the box – no one needs the database enums anyway.