first of all I'd like to tell you that you're terrific audience.
I'm making an application where I have model Foo
with table Foos
. And I'd like to give Foo another parameter, HABTM parameter, lets say Bar
. But I'd rather don't create table for Bar
. Because Bar
will have like 5 positions on start and in 5 years it will grow to maybe 7 positions or not at all. So I don't see a need to create another table and make CakePHP look into that table with another SELECT. Anyone have an idea this can be achieved ?
One solution I think is making an fixture for Bars
table and adding only Bars_Foos
table for real (it won't be big anyway). But I can't find a way to use test fixtures in normal Controller
Second solution is to save a JSON or serialized array in Foo
one field and move logic to model, but I don't know if it is best solution. Something like virtual field.
Real life example:
So I have like Bikes
. And every Bike
have its main_type
. Which is for now {"MTB","Road","Trekking","City","Downhill"}
. I know that in long time this list would not grow much. Maybe 2 or 5 positions in few years. Still it will relatively short.
(For those who say that there maybe a hundred of specialized bike types. I have another parameter column specialized_type
)
It needs to be a HABTM relation, but main_types
table will be very small, so Id like to avoid creating it and find a way for simpler solution.
Because
- It bothers MySQL for such small amount of data
- It complicates MySQL queries
- I have to make additional model for
MainType
- I have more models to unbind when I don't need most of data and would like use
recursive
- Insert here anything you'd like...