Please note: this project is inactive since early 2006
2.3.4 Relationship
A relation is attached to an entity, and describes how an entity is related
to another one.
Two kinds of relationships can be defined: simple and flattened
relationship. However flattened relationshipsare not supported/tested yet.
Simple relationships join their (source) entity to a destination entity.
A relation may have the following properties:
name
:
- the name of the relationship, unique within the entity.
deleteRule
:
- this specifies how the object should react when it
is deleted. Four options are possible options:
NULLIFY,
DELETE_DENY,
DELETE_CASCADE and
DELETE_NOACTION.
We will use the model AuthorBooks defined in
section 2.1.1, with entities Writer and
Books, to highlight the differences between those 4 values:
- if Book's relationship toAuthor has the delete rule
DELETE_NULLIFY, then when a book is deleted it is
automatically removed from the corresponding author's toBooks
relationship.
- If Author's relationship toBooks has the delete rule
DELETE_DENY, then if an author is marked for deletion while
it is still in relation with books, the deletion will be denied when you
try to make it persistent.
- If Author's relationship toBooks has the delete rule
DELETE_CASCADE, then the deletion of an author will
automatically delete the related books as well.
- You can also instructs the framework not to take any actions when an
object is deleted, with respect to its relationships. In this case, you
use the delete rule DELETE_NOACTION. This is however quite an
advanced setting and should be used with great care, since inappropriate
use of this setting can result in dangling references in your databases.
This will be enforced when an object is inserted/updated or when it is
deleted. See sections 4.4 and 4.6 for
further details.
isClassProperty
:
- tells whether the Relationship's key (i.e. its
name, for example: toBooks) is part of the class' API. It should
be set in most cases.
multiplicityLowerBound
, multiplicityUpperBound
:
- the multiplicty lower bound of a relationship defines the minimum number
of objects that should be in relation. If the lower bound is zero, none
are required: this is an optional relationship; if the lower
bound is one or more, this is a mandatory relationship.
The multiplicity upper bound defines the maximum allowed number of
objects in relations. It can be any positive number, given that it is
always greater or equal than the lower bound. As a special exception,
values -1
(minus one) or '*'
serve to indicate an
unconstrained upper bound.
The exact definition of to-one and to-many relationships
(see 2.2) are then: to-one relationship:
multiplicityUpperBound<=1
, to-many relationship:
multiplicityUpperBound>1
.
destinationEntity
:
- designates the name of the destination
entity.
joinSemantic
:
- the join's sematic can be either:
- (default) Inner join
- Full outer join
- Left outer join
- Right outer join
displayLabel
:
- same as for Attributes, above.
comment
:
- a comment, for maintainers of the model.
The full definition of a relationship implies that it defines at least one
join. However, this will not appear in PyModels, just in xml
models. It's not really part of Entity-Relationship Modelling, it is just a
mean to identify the correspondance between primary and foreign keys that
defines a relationship. For this reasons, we will wait until
section 2.5.5 to define them.
See also:
- section 2.6.2, which describes how relationships
should be designed, and why.
- section 2.3.3, which discusses namespace issues for
relationships and attributes.
Comments are welcome: Sebastien Bigaret / Modeling Home Page
Hosted by: