Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When designing objects you should look at their relations. From your example I see two objects:</p> <p>TODO list with properties:</p> <ul> <li>Id</li> <li>Url</li> <li>Password</li> </ul> <p>TODO item with properties:</p> <ul> <li>Id</li> <li>Content</li> </ul> <p>The URL property of your item does not seem to be bound to the item, rather to the list where the item belongs. </p> <p>If you look at this from the relations perspective, you can say that the TODO item "belongs" to a TODO list or rather a TODO list has in it a collection of TODO items.</p> <p>For this you have 1:N mapping between list and item entities (1 list has N items, 1 item belongs to 1 list).</p> <p>To record this relationship you could modify the TODO item table in this manner:</p> <pre><code>onlinelist.list onlinelist.item +----+-----+-------------+ +----+---------+--------+ | ID | URL | Password | | ID | Content | ListId | +----+-----+-------------+ +----+---------+--------+ | 1 | abc | rfk49gh34 | | 1 | apple | 1 | | 2 | pqr | 12345 | | 2 | banana | 3 | | 3 | xyz | password123 | | 3 | milk | 2 | +----+-----+-------------+ | 4 | beef | 1 | | 5 | egg | 1 | | 6 | pasta | 3 | | 7 | lemon | 2 | | 8 | carrot | 3 | +----+---------+--------+ </code></pre> <p>In case you want to share an item on multiple lists, you can no longer do this with only two tables, but you will have to create a mapping table.</p> <p>In that case you would leave the ListId from the onlinelist.item table and create a new one </p> <pre><code>onlinelist.mapping +----+--------+----------+ | ID | ListId | ItemId | +----+--------+----------+ | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 1 | (with more mapping going on) +----+--------+----------+ </code></pre>
 

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