Skip to Content
1
Jun 18, 2020 at 12:34 PM

CAP service Handler query $expand

941 Views

Hi SAP experts,

I've got a question, hoping you're able to help me out.

Given I've got 2 tables A and B, and an association from A -> B

entity A_Entity {
    key Id: Integer;
    Subject : String;
    LinkToB: Association to B_Entity on LinkToB.Id = Id;
}

entity B_Entity {
    key Id: Integer;
    date: Timestamp;
}

service service  {
    entity A as projection on A_Entity {
        *,
        LinkToB : redirected to B
    }

    entity B as projection on B_Entity {*}
}

For each service entity, i created a handler with a @Before event handler, it gets data from an external source, and puts it in it's own table in the HANA DB.

When I first do a call to B ...service/B , and then to A using ..service/A?$expand=B, then my data in B is filled correctly.

When I start with an empty database, and call ..service/A?$expand=B, this does not trigger the read event from B, so the expanded data is NULL.

Wow would you make this call 'eager', so CAP knows that the expand should trigger the read event on B?

On this moment the documentation is not helping me, stating:

The following GET requests will only trigger the READ handler for MyEntity. GET MyEntity GET MyEntity?$expand=myNavigation

Thanks,