Note that there are some explanatory texts on larger screens.

plurals
  1. POComplex Model Structure in Cakephp
    primarykey
    data
    text
    <p>I am creating a site that allows users to add a number of various items to their pages. These items can be very different from each other, such as text, images, numbers, etc. To handle this, I have one table that stores one entry for each item. The table has an id, the location of the item on the page, and the type of the item. I then have one table for each type of item which holds the more specific information about that item.</p> <p>What I want to do is to set up an association so that when the page loads, it grabs the items from the main table in order - which is simple - and then also grabs the associated information from the proper table of specific information.</p> <p>An example main_table could be:</p> <pre><code>id | location | type 1 | 1 | text 2 | 2 | image 3 | 3 | plot 4 | 4 | question </code></pre> <p>The table for text items may look like:</p> <pre><code>id | text | 1 | aaa | 2 | bbb | </code></pre> <p>The table for plots may look like:</p> <pre><code>id | type | datasets | 1 | bar | 3 2 | scatter | 2 </code></pre> <p>So, can I set up an association where the main_data model pulls in the one associated file from the proper table? I could set up a separate model that selected the table for the specific information based on a passed in variable and <a href="https://stackoverflow.com/questions/713736/can-a-model-have-multiple-tables-in-cakephp">set the source</a>, but I am not sure how you would pass the variable with the type information to the model, nor am I sure if I am approaching this properly?</p> <p>Thanks</p> <p>PS</p> <p>I had thought of the obvious - to combine the items into one table and simply have empty fields for everything not related to that item for each entry. So a text entry would still have columns for plot stuff, but they wouldn't be filled, etc. However, I wanted to be less wasteful of space - unless everyone thinks it would work better.</p>
    singulars
    1. This table or related slice is empty.
    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