Associations and Joins
Associations and Joins
Associations are a different type of gathering data together from multiple tables. We call them Join-on-demand.
This means that the data in the joined (associated) tables is not accessible directly at run time, but only on
demand. It is triggered only when the user needs that data. This is quite neat. Performance-wise, this can be a
game changer.
Association is conceptually Adhoc join or Join on demand. It helps us to achieve better performance and better
navigation. Very useful from Fiori apps perspective.
Cardinality in Associations:
When using an association to define a relationship between entities in a CDS document, you use
the cardinality to specify the type of relation, for example, one-to-one (to-one) or one-to-many (to-n); the
relationship is with respect to both the source and the target of the association.
The target cardinality is stated in the form of [ min .. max ], where max=* denotes infinity. If no cardinality is
specified, the default cardinality setting [ 0..1 ] is assumed. It is possible to specify the maximum cardinality of the
source of the association in the form [ maxs, min .. max], too, where maxs = * denotes infinity.
You use a Join when you want to combine data in the same read from the database. For example, if I am
displaying a list of Sales Orders I might want to get the vendor name along with the vendor id in the one read
which I use to display a list of Sales Order headers, because that's information I always need to show.
You use an association when you want to NAVIGATE from one entity to another in a UI. I don't always need to
drill down to every sales order. I can delay reading the Sales Order Items unless and until the user drills down to
them. So I want an association from my Sales Order header joined view to my Sales Order Item view. That sets
up an easy navigation but also that navigation won't be used unless the user needs it. So the overall UI will
perform better because it only reads the data it needs to.
Join:
Join is nothing but a conditional linkage between two data sources it may be a table or another in CDS view.
There are four types of join exist in the CDS view
Inner Join: Inner Join gives the matching value on both the table based on the join condition.
Left Outer Join: Left outer join gives the complete records of the Left data source and its corresponding targeted
data source(if found), if not then null entries.
Right outer Join: It gives the complete records of the Right data source and its corresponding left data source(if
found), if not then null entries.
Cross Join: As the name suggest this is the combination of all records.