Re: circular relationships ok?

From: Alexandr Savinov <spam_at_conceptoriented.com>
Date: Thu, 02 Mar 2006 18:26:30 +0100
Message-ID: <44072ac7\$1_at_news.fhg.de>

Volker Hetzer schrieb:
> Alexandr Savinov schrieb:

>> Volker Hetzer schrieb:
>>> Alexandr Savinov schrieb:
>>>> Volker Hetzer schrieb:
>>>>> Hi!
>>>>> Just in general, are circular relationships something that
>>>>> can always be avoided?
>>>>> Or, given a model with a circular relationship, possibly
>>>>> spanning several tables, is there a way to get rid of them?
>>>>
>>>> One approach consists in using the concept-oriented data model as
>>>> follows.
>>>>
>>>> 1. Order your tables so that if table A references records from
>>>> table B, then A is positioned under B. For example, if an order has
>>>> a field with its customer then you position them as follows:
>>>>
>>>> Customre
>>>>   |
>>>> Order
>>> So, what if A references B, B references C and C references A?

> Ok, I wasn't specific enough.
> what if one row (a) of Table A references a bunch of rows in B,
> each row (b) in B references a bunch of rows in C and each row (c) in
> C references zero or one row a' in A?
> Then a doesn't references itself, it references another row in the
> same table.

There is not such thing as "a row reference a bunch of rows". Any reference is a single thing. A row can reference only one row. Multi-valued attributes are implemented indirectly. In diagram this means changing direction of arrows, i.e., any downward arrow means a one-to-many relationship or multi-valued attribute.

I assume that you mean the following (maybe I am wrong):

a row from A is referenced from a bunch of rows in B, a row from B is referenced from a bunch of rows in C, each row (c) in C references zero or one row a' in A

Then it is modeled as follows:

A
| \
B |
| /
C

Here for each a in A we have many b in B. For each b in B we have many c in C. In the opposite direction: each c in C references one b in B and one a in A. Each b in B references one a in A.

>> Now assume that you have a cycle. This means that an element is a
>> member of itself and it is normally interpreted as a non-sense.

> In that case it isn't referencing itself, just another object in the
> same table.
>
> So, maybe it's not a circle but a spiral of an unknown number of turns.

If it is a loop then my opinion is that they should be permitted. Formally, we can avoid them but the life will be too hard. In addition, handling them is not a difficult task - loops (self-references) have clear and unambiguous semantics. So if an employee needs to reference a manager which is also an employee then it is not a problem.

If you have cycle then it is worse. It shows that something is wrong. However, I cannot exclude that sometimes this hack can be unavoidable. We need to separate theory and practice.

--
http://conceptoriented.com
Received on Thu Mar 02 2006 - 18:26:30 CET

Original text of this message