CDS Associations Part 3: To-One vs To-Many — Semantics and Performance
Preview · a free account unlocks the full lesson
Choose and use cardinality deliberately: what to-one and to-many mean for results, how to get one row per source when you need it, how to aggregate over to-many data, and how to keep text and time-dependent relations to-one.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 2 showed that path expressions become joins. This part is about the most important property of an association: how many target rows it can actually have per source row.
Cardinality tells the compiler, the optimizer, and frameworks like OData, Fiori and analytics tools what to expect from the relationship. It's a promise, not an enforced constraint — if [0..1] is declared but the target actually has two rows, duplicates still appear, and any consumer that trusted the promise ends up producing wrong results.
To-one associations are safe to use in lists. The customer of an order, the currency of an amount, the plant of an item — these have at most one target row, and paths through them can be used anywhere in the element list without changing the number of rows returned.
To-many associations, by contrast, are meant for navigation or aggregation rather than for flattening into a list. Items of an order, texts in all languages, price conditions — these all have many target rows, and to-many associations are the right tool for navigation ($expand, object pages), for aggregation (count, sum, min, max), and for existence-style filtering done in a controlled way. Unfiltered to-many paths should never go into list views.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.