RToOne objects describe a to-one relationship from an Entity to another. It derives from Relationship and overrides the following defaults:
Prop. | Type | Default | Comment |
---|---|---|---|
name |
string |
no default | The name is the only
mandatory arguments when instanciating a RToOne. Once set, it
should not be changed |
multiplicity |
sequence | [0,1] |
|
joinSemantic |
int |
0 |
see 2.4.7 for possible values |
(All other defaults are BaseRelationship's ones, cf.2.4.7)
Minimally, a RToOne needs a name
and a the name of the
destination entity, destination
.
Attributes src
and dst
, identifying source and destination
attributes, are automatically calculated if they are not supplied:
dst
is the primary key of the destination entity identified by
its name in attribute destination
.
src
is calculated from the destination entity's name stored in
the relationship's destination
attribute. It is a string like:
'fk<sourceEntityName>'
, possibly followed by a integer (such as in
'fkEmployee1'
) if the name already exists in the destination entity. In
fact, a PyModel does more than just computing a name: it also automatically
creates the corresponding foreign key in the source entity.
For example, a pymodel containing:
self.model.entities = [ Entity('Employee', properties=[ RToOne('toStore', 'Store'), # ... ]
automatically binds dst
to the destination entity 'Store'
's
primary key, and creates a AForeignKey
named 'fkStore'
in the
source entity 'Employee'
(unless such a property -either an attribute
or a relationship- already exists with this name, in which case it uses the
first unused name among 'fkStore1'
, 'fkStore2'
, etc.
Last, the 'inverse'
field of a RToOne (which designates the
inverse relationship defined in the destination entity) has some effect in the
automatic generation of AForeignKey: please refer to
2.4.7 for a full discussion on this topic.
Of course, you can specify your own source and destination attributes. In this
case, it is requires that both are supplied, and that they corrspond to
attributes (resp. AForeignKey
and APrimaryKey
attributes)
explicitly declared in the source/destination entities.
Comments are welcome: Sebastien Bigaret / Modeling Home Page