4.2.2.4. Reference

<reference> is a sub element of object and defines a relation with another object in the same package. Inside this object scope the name of the reference has to be unique. An object can contain any number of references.

Listing 4.16 <reference/> example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="https://metafactory.io/xsd/v1/model"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://metafactory.io/xsd/v1/model
                             https://metafactory.io/xsd/v1/model.xsd">

        <package name="yourModelPackage">
                <object name="yourObjectName01">
                        ...

                        <reference name="yourReferenceName" type="nameOfReferencedObject" multiplicity="0..n" notnull="true"></reference>

                        ...
                </object>
        <package/>
        ...
</model>

Syntax

<reference name=”” type=”” length=”” multiplicity=”” notnull=””> </reference>

Attributes

Table 4.12 attributes of <reference/>

Name

Details

Required

name

Name of the reference – has to be unique within the context of the object it is defined in.

mandatory

type

Data type of this reference (integer, boolean, string, other object…)

mandatory

multiplicity

Sets the multiplicity of the relation between the object of the reference and the object referred to.

multiplicity=”0..1| 1..1| 0..n| 1..n| n..n”

mandatory

notnull

This flag attribute tells whether its reference is allowed to be undefined (notnull=’FALSE”) or not (notnull=”TRUE”).

notnull=”false|true” with default “false”

optional

Exxample from the Bookstore application: an Author has a reference to Book, and the Book has references to Author and Category.

Listing 4.17 <reference/> example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="https://metafactory.io/xsd/v1/model"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://metafactory.io/xsd/v1/model
                             https://metafactory.io/xsd/v1/model.xsd">

        <package name="domain">

                <!--Assume we have authors who write books-->
                <object name="Author">
                        <attribute name="firstName" type="String" length="50" notnull="true" />
                        <attribute name="lastName" type="String" length="100" notnull="true" />

                        <reference name="book" type="Book" multiplicity="0..n"></reference>
                </object>

                <!--A book that is written by one author and the book belongs to a category-->
                <object name="Book">
                        <attribute name="name" type="String" length="100" notnull="true" />
                        <attribute name="description" type="String" length="255" notnull="true" />

                        <reference name="author" type="Author" multiplicity="1..1"></reference>
                        <reference name="category" type="Category" multiplicity="0..1" notnull="false">
                        </reference>
                </object>

                <object name="Category">
                        <attribute name="name" type="String" notnull="true" length="20" />
                        <attribute name="description" type="String" notnull="false" length="200" />
                        <reference name="book" type="Book" multiplicity="0..n"></reference>
                </object>
        </package>
</model>

Sub elements

The element <reference/> contains no sub elements.