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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 86 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |