I’m trying to implement this structure in my APP (i’ll use fantasy model names):
User hasMany Box
Box hasMany Item
Item hasOne Itemdata
"Item" have some metadata/info
"Itemdata" has 2 or 3 mediumblobs
This would be very easy if I want a db with 4 tables: users,boxes,items,itemdata.
In my db structure, due to amount of data, I’d like to split Itemdata in user-dependent tables, like this:
a) user1_itemdatas, user2_itemdatas ...
or at least,
b) myapp_user1.itemdatas, myapp_user2.itemdatas
(where myapp_user* are different DB).
How can I change on the fly the table in model “Itemdatas” when finding/reading data belonging to certain users?
Should I choose for custom query?
Ok I found a way:
I created another database, in app/Config/database.php I added a new connection:
Then in Itemdata model I put:
Finally when performing search:
An alternative can be to use user depending table prefix, instead of table name.