How to Add a Class
Let's consider the "CRM" mobile project in which we want to manage companies along with their employees. Let's start defining the company object with its own information.
Select the "Class" item from the Toolbar and place it in the Domain Model area. When you add a class in the Domain Model, by default WebRatio Platform adds one attribute to the class, which is the primary key. The primary key is mandatory, and that’s why WebRatio Platform provides this shortcut. The default key attribute is named "oid" and is an integer. Type a meaningful name for the class, such as "Company".
Let's add the properties we think that characterize a company (e.g.,Name, Nationality, Address, ... ). Right-click on the "Company" class and select "Add" and then the "Attribute" option.
How to Add an Attribute
Attributes are listed inside the class itself and are marked with an icon that indicates their role. If the attribute is one of the key attributes, a key symbol is added to the attribute icon. For each attribute it is necessary to specify a data type, which is the type of information to be stored.
Let's add all the other attributes for the "Company" class. You can add more than one Attribute at the same time by using the "Edit Class ..." feature. Right-click on the "Company" class and select the "Edit Class ..." option. In the opening dialog, press the "Add" button, then type a meaningful name for the attribute.
Repeat the same operation in order to add the "Address" attribute, the "Nationality" attribute and the "Logo" attribute. The "Logo" is a particular information because it is an image. We need to specify that thing in the type property by choosing "blob". Click on the drop-down menu corresponding to the "Type" property and select the "blob" option. Then press the "OK" button.
How to Add an Association
With the same procedure, we have created the "Employee" class with all its information. Let's add now an Association connecting the "Company" and the "Employee" classes.
Select the "Association" item from the Toolbar and click first on the "Company" class and then on the "Employee" class. An Association represents a connection between classes. The meaning of the association is conveyed by the Association's name and cardinality.
Once we have built our Association, let's change its cardinality. We want to specify that an employee belongs to a company and that a company has several employees. Select the "Company_Employee" Association. The cardinality specifies how many class instances can participate to an association. There are three types of cardinality:
- 1-1 Association.
- 1-* Association.
- *-* Association.
Our "Company_Employee" association is a 1-* association. As a matter of fact, we can have one or more "Employee" class instances for each "Company" class instance. Set the "Inverse Max Cardinality" property to "one".