Associations in CDS are relationships of one CDS entity to another CDS entity that is present in same CDS file or an entity residing in another CDS file, but within the same HDB module. CDS supports two types of Associations, Managed & Unmanaged Associations and you can create them graphically, or via the form based tabular editor for mass addition & editing of associations.
· Create associations graphically
From the version HANA2.0 SPS00 inwards, CDS graphical editor has introduced the capability to create associations graphically. Users can create an association by dragging the association tool (on the right side of the selected source entity symbol) to the desired target entity. This provides an easy to use, drawing-like experience for the users for creating association from one entity to another.
If the target entity resides in another CDS file, then import it by clicking on the ‘+’ button and then provide association details on the dialog that pops up after association is created.
· Create associations using form-based table editor
Since the very first release of CDS graphical editor on HANA1.0 SPS11, the form-based tabular editor is available for users to create CDS associations. Double click on the source entity’s symbol to see details screen, then click on ‘Associations’ tab to create or modify new or existing associations respectively using the form based editor.
The section below explains about creating associations using the form based editor:
To create associations for the entity (APJ_CUSTOMER) in our example, navigate to the tab ‘Associations’ (next to the ‘Elements’ tab where we created four elements earlier).
Click on the ‘+’ button and name the association ‘primaryVendor’. The next mandatory step is to select the target entity for this association i.e., the entity with which APJ_CUSTOMER entity will establish a relationship with. If you intend to create association with another entity present in the same file, then choose it from the drop down list under the column ‘Target Entity’. Instead, if the target entity resides in another CDS file, then choose the last option ‘Select from…’ and search for the required entity in the find dialog. Once found, select it and click on ‘Ok’.
After the target entity is selected, you can choose the type of association that you want to create. Managed associations are stored as a part of the database table definition where, the association keys for the managed association gets created as columns for the entity after the build of the hdb module. Whereas, the unmanaged associations are created at runtime when the table data is queried, depending on the ‘on condition’ provided to establish association amongst the source & target entities.
We have created two associations, one of each type (managed & unmanaged), as shown below. The target entity ‘SELLER’ resides in the same file, but the entity ‘PRODUCT’ has been imported from a file called ‘ProductDataModel.hdbcds’ which exists in the same hdb module as our current file in use.
Additionally, you can also set the source and target cardinalities for your associations.
When you navigate back to the main canvas or the diagram of your cds model, you will see the visual representation of all CDS artifacts and diagrammatic representations of their relationships with each other, like so:
Notice that the symbol for the entity ‘PRODUCT’ is visually different from that of other entities. All external artifacts or the imported artifacts that are used in current CDS file will be ‘read-only’ and will be represented by grey colored boxes throughout the cds file.