A050 – Create a relationship between 2 objects
What you will learn ?
The wizard Add Link allows to create a relationship between two objects.
- 2 objects must have been created with at least one functional key field each.
You must select the object that will contain the reference to the target object, i.e. the object that physically contain the foreign-key:
- Either by searching by the Administration menu business object, then Add a link
- Either via the object diagram containing the two objects, Link link icon and drawing an arrow between the two objects.
- Open the Application model diagram
- Choose the ObjectLink mode in the toolbar
- Draw a link from
This step describes how to set a link :
- Specify a default display tab order (for all relations of the object), by default if the order is not put an alphabetical sorting is done
- Replace the generated name with one respecting your naming rules (ex. cliAdresseFK to indicate a reference to the main address of the customer)
- Replace the physical name (ex. cli_adresse_fk)
- Indicate the rule to be applied:
– Unset the reference: if the foreign key is optional, the removal of the reference will clear foreign key (link is a composition, ex. the customer is without main address if the address is removed)
– Cascade Delete: Deleting the reference causes the removal of the object (link aggregation, ex. the removal of a main address deletes the customer)
– Impossible if referred : prohibits the removal of the referenced object if it is still referenced in another object (i.e. not remove a main address if the customer still exists)
– Do not use: do not apply the rule, to allow for example to create virtual links between objects through a specific filter
- Completing a cardinality
– Default relationship is 0,n . ex. an address can be used in any or all customers.
– Specifying a minimum limit, it will not allow to dereference unless the minimum.
– Specifying a maximum limit, it will not be possible to create more than this limit
ex: a “0,1” link indicates an address can be referenced only once or not at all.
- Indicate if the link is visible, hide the tab on the screen of the user
- Indicate if the copy cascade is available : only works if the link is a functional key of the object, the copy of the object is then used to copy each relationship (ex. an invoice and its line items)
- Indicate if the XML export function includes this link: When a complete technical export related objects is done, the data and all related one will be exported (ex. the address will be exported with all its customers who has this address)
- Associate: add the associate function in order for the user to associate mass data (ex. to assign an address to a set of customers in one operation)
- Specific Filter: optionally use this field to specify a filter in SQL, it will be added in search-related objects, you can use the keyword _[rowid] to identify the technical key _[rowid] of the main object (ex. t.cli_type = ‘PRO’ to list only the customer lead type having the selected address)
- Editable field: whether the foreign key is updatable, if the user can select / remove the reference (ex. the user can change the main address of a customer)
- Required field: whether the foreign key is required, if the reference is mandatory (ex. a customer must have a main address)
- field functional key: whether the foreign key is a functional key (ex. an invoice line is identified by its invoice and line number)
- If the object template has a more than one area, the area of the reference fields can be specified (opportunity to move later)
cliAdresseFKforeign key on the object
- With a physical name
- Editable, optional, non-functional key
- Visible panel, export XML, no Cascade copy
At the end of the wizard, the object presents the Objectfield tab with all referenced fields. It is possible to change the order of the fields taking care to leave the referenced fields orders under their foreign key order.
To change the link itself (cardinality, order, rule …), go to:
- Either the Administration menu Link by searching the object (ex. AppAdresse)
- By opening the referenced object in Administration/Business object (ex. AppAdresse) and going to the Link tab
Note: All business object has a Link tab that lists all relationships related to foreign keys.
- Find the link created in the menus or in yours items.
- Select the default panel to display : it is the first object tab to display. If the list is empty, it means that the object does not have object links.
NB: In case of object inheritance, the list does not necessarily show all possible links. The syntax in this case is as follows: ,
- Change Default panel in
AppAdresseobject to list the linked customers.
A n-n relationship is a business object that can include other fields (ex. start and end dates).
To create a n-n relationship between two business objects (ex. between a customer and his interests):
- We need to create a business object that will support the link (ex. AppClientInteret )
- And add two required links and functional keys (ex. a foreign key to the customer AppClient and another to interest AppInteret)
The same applies to more complex relationships by adding as many foreign keys as necessary in the business relationship object.
Creating a N-N relationship between the customer and the list of interests :
- Create the business object
- Add a relationship
AppClient: mandatory and functional key
- Add a relationship
AppInteret: mandatory and functional key
- These links must be visible, and delete cascade (if you remove a customer, interests will also be deleted)
- Check the option Associate to allow to associate mass interests to the customer.
Check the diagram for the presence of 3 links
- Black diamond for aggregation (delete cascade in case of removal)
- White diamond for a composition (set the reference to null in case of removal)
Once clearing the cache, a user with rights to the objects will add a home address to customers and interests.
Check the model
- Create a list with scores of interest: Sports, Movies, Travel …
- Create customers with and without address, with and without interest
In case of errors: correct configuration, clear the cache and re-test.