Dynamic table names

Hello all,


I am using cakephp 2.2 with croogo 1.3. I am in need of creating dynamic tables according to type of product types. for example for type 1


For second product when added it will be


and so on…

I have created them but when I use loadModel on these I get below error due to inflector rules:

Missing Database Table
Error: Database table product_scheme1_data_rows for model ProductScheme1DataRow was not found.

Please help resolving this or please let me know for better suggestions.

Thanx in Advance :slight_smile:

Why do you want multiple tables for same record type? Wouldn’t it be easier to keep common properties of each type as table columns, and all specific fields to product type in additional field saved in JSON format ?

like for an example id (int), name (varchar), description (varchar), price (dec) , metadata (text | blob | some native json type) would give you :

id => 10, name => product1, description=>product, price : 10,2 , metadata => {color: red, weight: 0,5kg} ,
id => 11, name => product2, description=>product, price : 10,2 , metadata => {water consumption : 20L , energy consumption: 40 KWh}

@Marcel Thanx for reply

Actually these are not simple products. These tables will be created dinamically from my application when a new product is added by admin in the system. Columns in these tables will be depending on the choice of admin which fields he wants to add. That is the reason I want a new table for each product type.

Saving data in JSON will create problems in searching, sorting and associations painful as there may be some fields which relate to other table values (Like dynamic form creator)

Thank You

Since last year mysql (I assume that this is your db) can search | sort etc by values saved in nested JSON objects.


If you insist to keep it way you want to keep it - use polymorphism - keep single model class switch tables inside this class etc.

Error that you are getting for 95% is caused by typos - perhaps in table names saved in db - if classes | files names are ok.


Thank you for reply.

I will surely learn about JSON. But my mysql is 5.5.50 and the reference link is for 5.7.

Please provide me some reference on Polymorphism also.

Thank You

http://bfy.tw/Ca4 <---- :wink:

@Marcel Thanx for help :smiley: :wink: