Skip to content

Commit 0f1e5b3

Browse files
committed
Remove "beta" and explain FK access
1 parent 344114b commit 0f1e5b3

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

advanced/odata.md

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ The second example is for a (record type) term in the [Communication vocabulary]
542542
```
543543

544544

545-
### Expressions <Beta /> { #expression-annotations }
545+
### Expressions { #expression-annotations }
546546

547547
If the value of an OData annotation is an [expression](../cds/cdl#expressions-as-annotation-values),
548548
the OData backend provides improved handling of references and automatic mapping from
@@ -681,12 +681,54 @@ Instead of relying on this copy mechanism, you can also explicitly annotate a fo
681681
annotate Books:author.ID with @Common.Text: ($self.author.name); // here $self is necessary
682682
```
683683

684-
::: warning Restriction concerning the foreign key elements of managed associations
684+
A path that addresses a key element in the target of a managed association is always rewritten
685+
to address the local foreign key element.
685686

686-
In an expression-valued annotation, it is not possible to reference the foreign key element
687-
of a managed association.
687+
Example:
688+
```cds
689+
service S {
690+
entity Travels {
691+
key id : Integer;
692+
status : Association to TravelStatus;
693+
};
694+
entity TravelStatus {
695+
key code : String(1) enum {Open = 'O'; Accepted = 'A'; Canceled = 'X'; };
696+
}
697+
@UI.CreateHidden : (travel.status.code != #Open) <!-- [!code highlight] -->
698+
entity Bookings {
699+
key id : Integer;
700+
travel : Association to Travels;
701+
}
702+
}
703+
```
704+
705+
Resulting OData API:
706+
```xml
707+
<Schema Namespace="S">
708+
<!-- ... -->
709+
<EntityType Name="Travels">
710+
<!-- ... -->
711+
<NavigationProperty Name="status" Type="S.TravelStatus"/>
712+
<Property Name="status_code" Type="Edm.String" MaxLength="1"/> <!-- [!code highlight] -->
713+
</EntityType>
714+
<EntityType Name="TravelStatus">
715+
<!-- ... -->
716+
</EntityType>
717+
<EntityType Name="Bookings">
718+
<!-- ... -->
719+
<NavigationProperty Name="travel" Type="S.Travels"/>
720+
</EntityType>
721+
<Annotations Target="S.Bookings">
722+
<Annotation Term="UI.CreateHidden">
723+
<Ne>
724+
<Path>travel/status_code</Path> <!-- [!code highlight] -->
725+
<String>O</String>
726+
</Ne>
727+
</Annotation>
728+
</Annotations>
729+
</Schema>
730+
```
688731

689-
:::
690732

691733
#### Expression Translation
692734

cds/cdl.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ Propagation of annotations can be stopped via value `null`, for example, `@anno:
13841384
:::
13851385

13861386

1387-
### Expressions as Annotation Values <Beta /> {#expressions-as-annotation-values}
1387+
### Expressions as Annotation Values {#expressions-as-annotation-values}
13881388

13891389
In order to use an expression as an annotation value, it must be enclosed in parentheses:
13901390
```cds
@@ -1481,7 +1481,7 @@ and a value written as expression `@aValueExpr: ( 11 )`, respectively.
14811481
If the annotation value is an expression, it is sometimes necessary to adapt references inside the expression
14821482
during propagation, for example, when a referenced element is renamed in a projection.
14831483
The compiler automatically takes care of the necessary rewriting. When a reference in an annotation expression
1484-
is rewritten, the `=` property is set to `true`.
1484+
is rewritten, the `=` property is adapted accordingly if the expression is a single reference, otherwise it is set to `true`.
14851485

14861486
Example:
14871487
```cds
@@ -1530,9 +1530,9 @@ rewritten to `@Common.Text: (descr)`.
15301530

15311531
::: info
15321532

1533-
There are situations where automatic rewriting doesn't work, resulting in the compiler error
1533+
There may be situations where automatic rewriting doesn't work, resulting in the compiler error
15341534
[`anno-missing-rewrite`](https://cap.cloud.sap/docs/cds/compiler/messages#anno-missing-rewrite).
1535-
Some of these situations are going to be addressed in upcoming releases.
1535+
In these cases you can overwrite the annotation with the correct expression in the new location.
15361536

15371537
:::
15381538

0 commit comments

Comments
 (0)