Imposing conditional entity relations

by Kishor Prakash   Last Updated March 28, 2018 22:05 PM

While working on an application, I am facing an issue. And I am not sure how to solve this.

For explanation I have managed to come up with a simple example below:

Consider a Grocery Store application.

  • It has a finite number(which means the items wont change often) of items.
  • Each item is different than other and has its own properties. In this Example they're:
    • Orange
    • Book
    • Chocolate
  • User would add one or more instances above items in to a BASKET.

enter image description here

From conventional wisdom I decided to represent this structure in Relational DB as following tables:

  • Created individual tables for ORANGE, BOOK, CHOCOLATE, and BASKET.
  • And created a Mapping tables between above with BASKET.

This works out so far good. Here is the issue.

Once user saves the basket, at the process of checkout the store would impose some rules/discounts which are set for individual scenario, For example:

  • If user's basket has 2 oranges, he can not checkout ROUND shaped chocolates.
  • If user checkout basket between 10 AM and 12PM he is not allowed checkout books from author: Dan Brown.
  • And some other rules, you can see where I am going with these.

User will not be aware of these above rules at the time of adding Items to basket. But these rules are imposed at the time of checkout.

My problem is HOW and WHERE should I store these rules? I can not hard code them in application. They have to be stored somewhere as guidelines to cashier at the time of checkout.

I am not sure if I could articulate my issue properly but I have simplified this as much as I could.

If any one have any solutions please let me know.

Related Questions

Is-a of an aggregation - entity relationship model

Updated October 09, 2018 13:05 PM

Rules engine suggestion for multiple if-then-else

Updated September 21, 2018 00:05 AM