I'm searching for a way to model 4 tables, keeping them consistent. 2 of the tables are a kind of 'enum++' types: they describe what is possible. The other 2 are each of them a concretization of the 'types'-tables. An example, simplified :) :
ActionType: describes the possible types of 'actions', e.g. cut vegables, cook, ...
name
ActionTypeResult: describes the result of each Type of action
nametype(<-Type.name)
So, for example, the result of cutting vegables would both be organic waste and cookable pieces of vegable (so 2 results). boiling would also have 2 results: cooked food and boiling water (you normally get rid of the boiling water, but it's the result of that step).
Now, I want to describe a recipe, which means, it has several ActionTypes, but the Result of an ActionType is the input of the next one. So:
I may have a Recipe entity, which consists of
CookingSteps, which links to the ActionType - to know what kind of step it is, and which kind of Results the step has.
CookingFlows, which are the Results (the products) that can be the input of a next CookingStep.
So, one might do this:
Recipe:
name
CookingStep:
recipe(<-Recipe.name)title(well, you can give the steps a name, dependent on the recipe :) )
CookingFlow:
step(<-CookingStep.title, this is the source of the flow)recipe(<-Recipe.name, not sure if we really need that, since we know it because it is already linked bystep, I didn't include in the diagram below)result(<-ActionTypeResult.name, so know which of the different flows we're talking about)flows to(<-CookingStep.title, so we know where to this flows).
Now, doing this, I see redundancy in the recipe relationships, but it is also possible to 'cheat': a CookingStep of type cut vegables can have a relationship with a CookingFlow which has a result boiling water or boiled food. I want that cheating to be disallowed.
The question is: how to model this properly?
The problem is that it can lead to inconstent data (the cheating). The main problem here I have is: having a certain CookingStep, I have both an ActionType and a CookingFlow. This is fine. However, The ActionTypeResult I have in the CookingFlow in this case must be one that is allowed by the ActionType defined by the CookingStep. I want the right ActionType to be enforced on the CookingFlow of the same CookingStep. I can use triggers on the DB to check if this is right; I was mainly wondering if one could model it without triggers.
