diff --git a/bookstore/srv/mashup.cds b/bookstore/srv/mashup.cds index 109f8a82..1099e29f 100644 --- a/bookstore/srv/mashup.cds +++ b/bookstore/srv/mashup.cds @@ -20,9 +20,11 @@ extend Books with { // // Extend Orders with Books as Products // -using { sap.capire.orders.Orders_Items } from '@capire/orders'; -extend Orders_Items with { - book : Association to Books on product.ID = book.ID +using { sap.capire.orders.Orders } from '@capire/orders'; +extend Orders with { + extend Items with { + book : Association to Books on product.ID = book.ID + } } diff --git a/orders/app/fiori.cds b/orders/app/fiori.cds index 94b7f5c2..e3644ede 100644 --- a/orders/app/fiori.cds +++ b/orders/app/fiori.cds @@ -68,7 +68,7 @@ annotate OrdersService.Orders with @( -annotate OrdersService.Orders_Items with @( +annotate OrdersService.Orders.Items with @( UI: { LineItem: [ {Value: product_ID, Label:'Product ID'}, diff --git a/orders/db/data/sap.capire.orders-Orders_Items.csv b/orders/db/data/sap.capire.orders-Orders.Items.csv similarity index 100% rename from orders/db/data/sap.capire.orders-Orders_Items.csv rename to orders/db/data/sap.capire.orders-Orders.Items.csv diff --git a/orders/db/schema.cds b/orders/db/schema.cds index b85e3a0d..85effeaf 100644 --- a/orders/db/schema.cds +++ b/orders/db/schema.cds @@ -3,27 +3,22 @@ namespace sap.capire.orders; entity Orders : cuid, managed { OrderNo : String @title:'Order Number'; //> readable key - Items : Composition of many Orders_Items on Items.up_ = $self; + Items : Composition of many { + key ID : UUID; + product : Association to Products; + quantity : Integer; + title : String; //> intentionally replicated as snapshot from product.title + price : Double; //> materialized calculated field + }; buyer : User; currency : Currency; } -entity Orders_Items { - key ID : UUID; - up_ : Association to Orders; - product : Association to Products; - quantity : Integer; - title : String; //> intentionally replicated as snapshot from product.title - price : Double; -} - /** This is a stand-in for arbitrary ordered Products */ entity Products @(cds.persistence.skip:'always') { key ID : String; } - - // this is to ensure we have filled-in currencies using from '@capire/common'; diff --git a/orders/package.json b/orders/package.json index 7415f469..1b92b46b 100644 --- a/orders/package.json +++ b/orders/package.json @@ -2,6 +2,7 @@ "name": "@capire/orders", "version": "1.0.0", "dependencies": { + "@capire/common": "*", "@sap/cds": "^5" } } \ No newline at end of file diff --git a/orders/srv/orders-service.js b/orders/srv/orders-service.js index 434c9e20..f395c077 100644 --- a/orders/srv/orders-service.js +++ b/orders/srv/orders-service.js @@ -3,7 +3,7 @@ class OrdersService extends cds.ApplicationService { /** register custom handlers */ init(){ - const { Orders_Items:OrderItems } = this.entities + const { 'Orders.Items':OrderItems } = this.entities this.before ('UPDATE', 'Orders', async function(req) { const { ID, Items } = req.data diff --git a/test/hierarchical-data.test.js b/test/hierarchical-data.test.js index 00a4a2b1..2e5e86e5 100644 --- a/test/hierarchical-data.test.js +++ b/test/hierarchical-data.test.js @@ -1,8 +1,6 @@ const cds = require('@sap/cds/lib') const {expect} = cds.test -const { parse:cdr } = cds.ql - // should become cds.compile(...) when cds5 is released const model = cds.compile.to.csn (` entity Categories { @@ -78,9 +76,7 @@ describe('Hierarchical Data', ()=>{ { ID:101, name:'Cat' }, { ID:108, name:'Catweazle' } ] - return 'skipped as this will be fixed in a newer cds version' - if (cdr) expect ( await SELECT.from(Cats) ).to.containSubset (expected) - else expect ( await SELECT.from(Cats) ).to.eql (expected) + expect ( await SELECT`ID,name`.from(Cats) ).to.eql (expected) }) })