User's Manual

92 Chapter 9. Persistence Tutorial
9.8. Link Attributes
When modeling many real-world problems, it is common to encounter situations that require associ-
ating data with a link between two objects. This document describes how to model these situations
using the persistence system.
9.8.1. Introduction
When creating a model for use in a particular domain, there are usually cases in which a simple
association between two object types will not suffice. A Group may contain Users through a members
Association (see Section 9.3 Associations), and for each member that Group may want to record the
date on which the User became a member of the Group. This is a case in which the link between
two objects must carry more information than just that the two objects are associated. The UML
terminology for this is a qualified association and it is described with the following model.
____________ ____________
| Group | | User |
|------------| |------------|
| | n n | |
| |------------------------>| |
| | | members | |
|____________| | |____________|
|
|
|
________|________
| |
|-----------------|
| membershipDate |
| |
|_________________|
A model like the one depicted above can be created in sql with the following 3 tables.
create table groups (
group_id integer primary key;
name varchar(300);
....
);
create table users (
user_id integer primary key;
name varchar(300);
email varchar(100);
....
);
create table group_member_map (
group_id integer references groups;
member_id integer references users;
membership_date date default sysdate;
primary key (group_id, member_id);
);
This association can then easily be transformed to PDL through the use of the association keyword.
When defining an association between two objects using the association block, it is possible to add
extra properties that can store information associated with a particular link between two objects.
object type Group {
BigInteger[1..1] id = groups.group_id;