OpenWGA 7.10 - OpenWGA Concepts and Features
Design and development » HDBModel framework » Relations in HDBModelDefining a relation
Inside the document definition file hdb-model.xml you can define a relation by specifying a <relation> tag inside the <content> tag of the content that should own the relation.
A good use on the example data introduced on the Basics page would be to define a relation on the "project" document that points to a "customer" document, so a project can be assigned to belong to a customer:
<content contentclass="project">
<relation name="customer" targetclass="customer"/>
</content>
There are two mandatory attributes on this tag:
- The attribute name gives a name to the relation by which it may be referenced
- The attribute targetclass defines the content class of the documents that this relation should target. As we always want to target a "customer" document - and nothing else - it makes sense to restrict a relation to this content class
This defines a single relation that points from one project document to one customer documents.
If we want the relation to target multiple target documents then we may make it a relation group. We do this by giving it the attribute group="true".
An example would be if we want "bill" documents to hold relations to all "task" documents that are billed:
<content contentclass="bill">
<relation name="billedtasks" targetclass="task" group="true"/>
</content>
That way the relation will not get stored as a single relation but a relation group of the given name.
In some situations we do not want a relation to target each and every document of the given target class. We want it to be reduced to some "parent context".
Again the bills-to-task relation is a good example for this. We want it to target only tasks of the same project. We do not want to have bills target tasks from other projects than the one the bill belongs to.
We can enforce such a reduction by the declaration of a base class. Looking from the content for whom we declare the relation the base class must be the class of a parent content. It is the content to which the scope of target documents should be reduced. So in the case of the example this would be the class "project"
<content contentclass="bill">
<relation name="billedtasks" targetclass="task" group="true" baseclass="project"/>
</content>
Now to conclude what we defined: We defined that "bill" documents have a relation group name "billedtasks", where an unlimited number of relations may point to "task" documents of the same project.