cap-js / cds-dbs

Monorepo for SQL Database Services for CAP
https://cap.cloud.sap/docs/
Apache License 2.0
37 stars 11 forks source link

fix: dont use virtual key for `UPDATE … where (<key>) in <subquery>` #800

Closed patricebender closed 2 months ago

patricebender commented 2 months ago

For a draft enabled model:

namespace my;

entity Books {
  key ID : Integer;
  title  : String;
  stock  : Integer;
  author : Association to Authors;
}

entity Authors {
  key ID : Integer;
  name   : String;
  alive  : Boolean;
}

service CatalogService {
    @odata.draft.enabled
    @readonly entity Books as projection on my.Books;

    @readonly entity Authors as projection on my.Authors;
}

my.Books will have a field:

        "IsActiveEntity": {
          "type": "cds.Boolean",
          "key": true,
          "default": {
            "val": true
          },
          "@UI.Hidden": true
        },

which is marked as virtual by the lean draft implementation. This virtual key must not be part of the primary key matching which is done for a path expression in a UPDATE.where:

https://github.com/cap-js/cds-dbs/blob/982b8b796da4b577c5641039d2036816209c0437/db-service/test/cqn4sql/UPDATE.test.js#L73-L97

TODO:

patricebender commented 2 months ago

also check if UPDATEs on tables w/o primary keys cause issues