Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create dynamic 'types' in database
    primarykey
    data
    text
    <p>My question relates to a php website with a mysql database. </p> <p>Currently in the database we have a 'token' entity</p> <p>a token can hold 0 or more 'object' entities and each of these objects can be of type x, y, z</p> <p>so</p> <pre><code>---------- | Token | |--------| -------------- |token_object| | | |tokenID | |objectID | -------------- ------------ | object | | | |objectType| ------------ ------------ --------- --------- | objectX | |objectY| |objectZ| | | | | | | ------------ --------- --------- </code></pre> <p>Now this works okish, because when I want the data from an object which, due to the nature of our caching system, is almost always one object at the time I can just make two queries to get the data from object and objectX/Y/Z</p> <pre><code>(SELECT * FROM object WHERE id = $id) </code></pre> <p>and</p> <pre><code>switch($objectType) case 'objectX': SELECT * from ObjectX WHERE id = $id case 'objectY': etc etc.. </code></pre> <p>But now I've been asked to allow users of the website to create new object types, ie objectA/B etc.</p> <p>I could just create a new objectXn table for each new object type, and by choosing a good value for objectType that would work</p> <pre><code>(SELECT * FROM $objectType WHERE blabla) </code></pre> <p>but that doesn't seem to be a very clean solution, especially the creation of new tables</p> <p>Are there any better solutions?</p> <p>Worth noting is that I expect that there are a lot of objects relative to tokens and that the creation of extra object types won't happen a lot/almost never</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload