SAP CAP Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 
qmacro
Developer Advocate
Developer Advocate
747

When defining a service, it's common to expose targets that are related. The classic example might be books and authors:

using bookshop as my from '../db/schema';

service AdminService {
  entity ListOfBooks as projection on my.Books excluding { price };
  entity Books       as projection on my.Books;
  entity Authors     as projection on my.Authors;
}

Given the expected relationship between Books and Authors at the schema level, the problem here is that the compiler cannot automatically determine whether Authors.books should refer to ListOfBooks or Books, and emits an error.

To resolve the ambiguity we can use the redirected to for the element, like this, where we say that Authors.books should refer to Books:

using bookshop as my from '../db/schema';

service AdminService {
  entity ListOfBooks as projection on my.Books excluding { price };
  entity Books       as projection on my.Books;

  entity Authors     as
    projection on my.Authors {
      *,
      books : redirected to Books
    };
}

Instead of creating an explicit block for the authors projection in order to add the redirected to to the books element, we can also use an annotation to point to the desired association target:

using bookshop as my from '../db/schema';

service AdminService {
  entity ListOfBooks as projection on my.Books;

  @this.is.the.target
  entity Books       as projection on my.Books;

  entity Authors     as projection on my.Authors;
}

Clearly the annotation is not @this.is.the.target, but it shows where and how we would employ it. But what is the annotation name?

This is a question from the June Developer Challenge on CAP Knowledge. And don't forget: always submit your answer as a hash, on its own - read the Taking part section of the intro post for more info. At the end of today, this question will be updated with links to further reading on this topic.

Further info:

29 Comments
soheil_st
Explorer
0 Likes

448e568235ca511e6d8376676445c3961b47d6b446703f1eedbedcf69450caa9

SachinArtani
Active Participant
0 Likes

2749615ec0ed277b262b3b7526c2a4827a7b28267109113fb074f5f0b85038f9

berkaydurmaz
Explorer
0 Likes

69eb6ef91fbdfaf68e66d754698fed30822d709d9cc6500f01e0892a9a3ea950

VishnAndr
Active Contributor
0 Likes

3cbd87a487e32d6c12510ebc6dec10e6592855e3701aff934530dc76b06b49b9

YLN
Explorer
0 Likes

630bd842ccaa966d133da92690c6834047fd9a0760aa8d58a0661b0e23f3f0ee

0 Likes

6d9703cf9487d7099015d2e87f7de8cf44ed91ede1ceddc30ccf6d1c2da04c9b

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Likes

e6b193b06bbeaf31c32f2db51a3cc8db77df0f42031c9a648f9c4fa4cc29a409

Raphael
Explorer
0 Likes

a677f7084f80addf9410cf45c0e81952ea32f1ba5a6c51a272ffacef7be3194d

Caisi
Explorer
0 Likes

37f3e05a08b1fee6fcf1484fc4365d338a87e20b58ef0ea1d3c171760b638878

kasch-code
Participant
0 Likes

d46cd65a130421b5708c69db57c15c35732f2058e119c63213668bedd42b7d86

Chaimae_Chairi27
Participant
0 Likes

dfb0b9fc9de1974b31f7d6b344f15dded17fa8336f523b7863131e85510ca841

furkan5
Explorer
0 Likes

d33534c7072b0a2cf5ee7c8b8685418266d64c212090dd24b8bef032272d0fed

mvaibhav
Contributor
0 Likes

de7a3223ff87df678de9ecb20c393eafa94c7239e9f09305d86ce441da52feb7

Rupesh_Kumar25
Explorer
0 Likes

d8e5ddfc7e9d30142bdf7df87baa40c11fb15d4381b9c5dea311b38f98c3f51f

parthasaradhi
Explorer
0 Likes

ce2f7ad2ca609ab7ad811364eb67b36379df9ec180b05e06444483d902f84075

Joery
Participant
0 Likes

d2c5c396d57f8437c8eae8bb3eaf344d18d98184575ac944db1d1b02faf7e175

MioYasutake
SAP Champion
SAP Champion
0 Likes

6fc073e4375d62dbd89e952d3c1ab682b74b7c64cce44b0be9c32c41b1f165aa

lidavidlee
Explorer
0 Likes

56a3df6f2f52b176ac2b2dc17f9ce42f1db0a96e1c9feb3554eba3f9806c0844

NakulG
Explorer
0 Likes

54d29ebdbf0137634c3461f1fe020efd9e61920234ff5d066f9145003504cc56

MatLakaemper
Participant
0 Likes

80c652c10d949330cb1c7e517fdabcf37a1aaf8609990a5a78e9ac2a8d49f555

Yogananda
Product and Topic Expert
Product and Topic Expert
0 Likes

fc6026c50bb2499eaeeb6a5e1d810a630ca1aee84f63bedd2689ddbded888309

Ihor_Haranichev
Participant
0 Likes

d05d1e93bc839b44fbb595a08a07e9384b5b6041b208848a67975e9969e41df8

SergioG_TX
SAP Champion
SAP Champion
0 Likes

72f71758741f27f4f0f8f2f9d22ef354649539348b6820d1085e88ecb62bb6b5

aelghannam
Participant
0 Likes

ffec883e5409c60a553ea87689ddd6656fb408d0dba9a377fcb7b5875defbe33

shotokka
Explorer
0 Likes

1f6a55b80d3cebef0529e83ac5ba145a5bd00e571a1d162a5df5534e1370de10

ajmaradiaga
Developer Advocate
Developer Advocate
0 Likes

f8481422a2ee16d266d625d0bc557aa4d903685945474cefe3b4a80388a4dde3

RajeshOlive
Explorer
0 Likes

bcfb8f77415d0bbab15f45d7e7fa407417a79907772ef2378c1ee7f7a332915a

sarvesh_agarwal
Explorer
0 Likes
5f606f412e3a71df6cfc33ea3865922784f6beb9b1a388e7c038b67acfe62159
GauravPhadnis
Product and Topic Expert
Product and Topic Expert
0 Likes

b5d1e4764868e4a73ac100b7ff26b352e9d341598c89d261cdacd737c0c89219