-
Notifications
You must be signed in to change notification settings - Fork 4
Relation
In JOR, relation means a group of attributes. Attributes are grouped together because they have certain relationships in business semantics.
Relation has its mathematics definition. It is a relationship between sets of values. While a set of values is defined as Data Domain in JOR. As long as a data domain is assigned to an attribute through data element, the possible values of the attribute forms a value set. The set of values can be related to other set of values to form ordered pairs or tuples.
Technically, relation is the synonym of DB table. When you create a relation in JOR, a underlying DB table with the same name is created. The attributes in the relation are mapped to the table columns.
In the modeling tool, go to the 'Relation' tab. The left list shows the 10 latest relations in the system. You can run a fuzzy search which filters in names and descriptions. Click the '+' button on the top right, you can create a new relation.
You must give a unique name which should begin with 'r_'. You may also give some description.
You add attributes by assigning name and data element pairs. Although not recommended, you can switch to data type mode by clicking the bulb button, which allows you to add an attribute with elementary data types. This is designed for some technique attributes which may not be worth to create data elements for.
At least one of the attribute must be checked as primary key(PK). If you don't want any primary key from business perspective, you can add an integer type attribute, like a counter, and check it as both primary key(PK) and auto increment(AI). Now it acts as a surrogate key, and you don't need care about its uniqueness. For example, the address ID is defined in such way in relation 'r_address'.
A relation can have associations to other relations. Just like we join 2 tables in SQL, association is described using fields from left table mapped to the right table. Unlike join, association doesn't take effect until attributes from the associated relations are requested.
You add an association by giving a unique association name and the associated right relation. The left relation refers to itself. The cardinality is used to describe the possible number of items in the right relation. 4 cardinality options are given:
- [0..1]: The right relation could have no or only one item.
- [1..1]: The right relation must have one and only one item.
- [0..n]: The right relation could have no or many items.
- [1..n]: The right relation could have at least one item or many items.
Foreign key check is provided only for the cardinality '[1..1]' and '[1..n]'. If checked, when new value is entered into the relation, the value of the mapping fields is checked against the items in the right relation.
Click the 'Field Mapping' button in the 'Action' column, a dialog box pops up, in which you can maintain the mapping of fields between the left relation and the right relation. You cannot save the relation if the field mapping is missing.
You can add or delete attributes. The changes will be effective in DB immediately.
When you delete an attribute, it will also remove the column in the underlying DB table. The data of the remaining columns still exists. When you add an attribute, the DB table is also extended with the new field, and its value is set to null for all existing items. When you change the attribute name, the DB column name is also changed, and its data remains. If you change the primary keys, it will trigger the data conversion in the DB, which could be failed. Then, you need to manually correct the errors.
Changing of associations may also introduce inconsistencies.
For example, if you add a foreign key check to an association which already have data in both relations,
then, JOR cannot permit the right relation contains the value in the left relation.
If you delete an association, some query requests could be impacted.
In any cases the inconsistencies happen, you need to manually correct them.