Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This concept should get you going:</p> <p><img src="https://i.stack.imgur.com/fblRq.png" alt="enter image description here"></p> <p>The user can see the product if:</p> <ul> <li>the corresponding row exists in USER_GROUP_PRODUCT</li> <li>or PRODUCT.PUBLIC is TRUE (and user is in at least one group, if I understand your question correctly).</li> </ul> <p>There are 2 key points to consider about this model:</p> <ol> <li>Liberal usage of <strong>identifying</strong> relationships - primary keys of parents are "migrated" within primary keys of children, which enables "merging" of GROUP_ID at the bottom USER_GROUP_PRODUCT. This is what allows the DBMS to enforce the constraint that both user and product have to belong to the <strong>same</strong> group to be mutually visible. Usage of <em>non-identifying</em> relationships and surrogate keys would prevent the DBMS from being able to enforce that directly (you'd have to write custom triggers).</li> <li>Usage of PRODUCT.PUBLIC - you'll have to treat this field as "magic" in your client code. The alternative is to simply fill the USER_GROUP_PRODUCT with all the possible combinations, but this approach is fragile in case a new user is added - it would not automatically see the product unless you update the USER_GROUP_PRODUCT as well, but how would you know you need to update it unless you have a field such as PRODUCT.PUBLIC? So if you can't avoid PRODUCT.PUBLIC anyway, why not treat it specially and save some storage space in the database?</li> </ol>
    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. 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