Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like a many-many relationship for "what users have seen what projects", best implemented with a table with exactly two columns -- a foreign key into the users table and one into the projects table. When a project is created you don't yet add entries to this table (unless you can identify a certain user as the creator who's deemed to have seen the project, in which case you do add that one entry) -- you add an entry (U, P) each time the "user U has seen project P" occurs. When a project is modified you remove all entries in the table regarding that project (again, except maybe the one for the user who is doing the modification, if you know who).</p> <p>Need the SQL for this table's schema and the operations I've outlined in words?</p> <p><strong>Edit</strong>: a commenter requested the SQL, so (assuming InnoDb, in the case of mysql), assuming tables user and project have int primary keys uid and pid respectively:</p> <pre><code>create table Seen (uid int, pid int, foreign key uid references user(uid) on delete cascade, foreign key pid references project(pid) on delete cascade, primary key (uid, pid)) </code></pre> <p>When an existing project with a pid of P is modified, so no user is now deemed to have "seen" it, <code>delete from Seen where pid=P</code> (i.e., remove all entries for P from this table); if the modification is made by user U, so user U is actually deemed to have seen it, you can add <code>and uid!=U</code> to the <code>where</code> clause of the <code>delete</code>.</p> <p>To mark the fact that a certain user U has now seen project P, <code>insert ignore into Seen(uid, pid) values (U, P)</code> (the <code>ignore</code> part means "do nothing if the row was already there", so that recording the "seen" conditions more than once is innocuous, although of course redundant).</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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