Apologies for the less than ideal title; had a hard time coming up with something.
Three entities: Products
, Clients
and Client_Product_Authorization
.
A Client
has access to many Products
.
A Product
is accessed by many Clients
.
A Client_Product_Authorization
authorizes a Client
to access a Product
.
We have 100,000+ Products
(virtual goods) and managing Client_Product_Authorizations
becomes a very labor intensive task. So we have Products
that is a container of other Products
. Example:
Product X is a container for Products 1 through 2000.
So, by creating a Client_Product_Authorization
granting a Client
the Product
X, we are indirectly providing for the client to access products 1 through 2000. Mind that product 1 might be contained in different container products (so, yes, it is a many-to-many self relationship).
Here is the entity level data model:
The advantage of this mechanism is that we can just change the composition of Product
X (adding or removing other products) and it automatically adjusts the product list available to the clients authorized to Product
X. Managing awarding access to our large product-base is a matter of selecting a few container products.
The disadvantage is that it now became harder (in terms of creating a SQL statement, because of the many-to-many self-relationship) to know what the Client
is actually authorized to see (as in the individual non-container products). As in:
Product Z is a container for Product X and Product Y
Product X is a container for Products 1 through 2000
Product Y is a container for Products 2001 through 5000
What are the actual non-container products a client authorized to Product Z can see?
Products 1 through 2000 and 2001 through 5000.
I would like to make the list of non-container products a client is authorized for to be materialized in some way. So that questions like:
Should
Client
ABC be allowed to seeProduct
78?OR
What products is
Client
ABC authorized to see?
can be easily responded with a query.
The goal is to make the job of software trying to determine the list of products accessible to a client a simple mechanism, instead of requiring a traversal through all container products, their sub-container products, etc etc etc.
Three questions:
a) Is there a better data-model for this scenario?
b) Is there a different mechanism to simplify the management of access authorization for this large set of products?
c) How would you go about making the obtention of the list of non-container products available to a client as simple as possible?
I appreciate the collective's input. Thanks in advance!
Update: Limiting the number of nested products is not an option for business reasons.