Arpan Das
Arpan Das

Reputation: 1037

Dynamic 1 to many db design -

I have 2 tables like: And I am using mysql.

1. product

enter image description here

2. template

enter image description here

Now 1 product can have multiple templates associated with it. Which I can achieve by creating a mapping table like:

product_template

enter image description here

Now based on some dynamic condition I need to select a template for the product for each request it is serving for:

Condition like

  1. If request came from region-x then select template 2 for product 1.
  2. If request came from region-y then select template 1 for product 1.

where I have multiple region in my DB . And to morrow if I want to add another condition that can be done by changes in DB only. Is there any design I should follow to open by DB design extendable.

Upvotes: 0

Views: 37

Answers (1)

Cosmin
Cosmin

Reputation: 1490

Instead of the product_id + template_id table you can have a general connection table and add a type, for instance :

template_id  external_id  type
1            1            'product'
1            2            'product'
1            1            'user'

Then, you can add in this table what you want as type in the future. You just need to rewrite the joins accordingly to the type.

Upvotes: 1

Related Questions