cancel
Showing results for 
Search instead for 
Did you mean: 

How to follow associations in @restrict?

klaus_kopecz
Participant
0 Kudos

I want to follow an association within a @restrict condition when defining a service. I'm using SQLIte, cds 3.31.2 and a product model listed below.

A variant which is working, is the following:

service CatalogService {
  entity Products @(restrict: [{grant: 'READ', where: 'currency_code = $user.currency'} ]) 
...

I would have expected (and the documentation is suggesting this) that I can follow associations, like currency.code in my where expression. Otherwise, I need to know the technical details how CAP is generating database tables.

However, If I try this:

entity Products @(restrict: [{grant: 'READ', where: 'currency.code = $user.currency'} ]) 
...

I'm getting, the following error:

SQLITE_ERROR: no such column: localized_CatalogService_Products.currency.code

Which is weird anyway ,because it occurs for a loclized-table.

What is the correct and recommended ways to follow associations in grant-where conditions?

Here is my underlying product model

using {managed, Currency} from'@sap/cds/common';
entity Products : managed {
  key ID : Integer;
  name: localized String(100) not null;
  stock : Integer;
  price : Decimal(9, 2);
  currency : Currency;
}

Accepted Solutions (0)

Answers (1)

Answers (1)

david_kunz2
Advisor
Advisor
0 Kudos

Hi,

Unfortunately, path expressions only work with SAP HANA.

Best regards,
David