Creating and Object-Role Model - Part 3 - External Constraints

Wednesday, June 10, 2009 by Mark Murphy
Previously I talked about some ORM basics, and internal constraints.  With just these parts one can build a fairly sophisticated information model.  But there are times that one fact type will depend on another in some way.  For example say I want to model a telephone survey of some type.  A caller will make phone calls and ask the person on the other end some questions.  The answers to these questions will be recorded either as a multiple-choice selection, or as a free-form "essay" type answer.  For a given question, an answer must be recorded in exactly one of these two forms.  We have a couple things going on here, so I am going to break it up into logical parts.

First an Answer is given for a Question during a Call.  This is not the typical binary fact type that we have been dealing with so far, but in ORM we can still record these fact types and give them internal constraints.  Going to the diagram we have the following:

There are no external constraints here, but you can get a decent idea of just what can be modeled with more advanced fact types.  Note the mandatory constraint requiring a question and a call for each answer given, and the uniqueness constraint saying that a question asked during a specific call identifies a particular answer.

Here is another way to model the same information using binary fact types and an external unique constraint:

In this case an external uniqueness constraint is applied to the Call and Question roles of the Answer applies to Call and Answer given for Question fact types.  There is a difference between these two models though.  Can you detect it?  In the first model, the same answer can be given for more than one question as long as it is given on a different call.  Functionally this means that in the second model, each answer given is it's own answer with it's own answer id.  I modeled this in Visio for Enterprise Architects.  And though I would like to put a uniqueness constraint on the Answer role in the first model, Visio does not allow that.  I have not tried this with other tools.

What about that part where I want to require either a multiple-choice answer or a text answer?  I have another external constraint for you.  Here is the diagram.


This is a mandatory constraint on the answer role relating the two fact types.  This means that an Answer bust have a choice, or some text.  Still it could have both, so I need another constraint.  One that means that I can't have more than one of each of the related roles in play.  I have not talked about this constraint type yet because it really doesn't apply to internal constraints.  It is called an exclusion constraint, and this is what it looks like on the diagram.


Note that both the mandatory and the exclusion constraints are attached to the answer role while the uniqueness constraint is on the other role.  Note that for a given answer, the answer cannot be unique across the two fact types, it has to be the same on the same fact.  The uniqueness constraint applies to the roles it is attached to.  Mandatory and exclusion constraints apply to the other role.  For a given Answer (role the constraint is attached to, at most one of the fact types is allowed.  If we combine the mandatory and exclusion fact types we get an exclusive or construct that would mean for each Answer, exactly one of the two related fact types are required.  See the diagram:


It is hard to see, but if you look closely you will see the X in the circle behind the dot.  Note also, that these constraints can be extended beyond two fact types to mean exactly 1 of n or at least 1 of n or no more than 1 of n.

Next time I will talk about ring constraints and something that no case tool based on ER models (that I have used) can do.

Comments for Creating and Object-Role Model - Part 3 - External Constraints

Leave a comment





Captcha