Skip to content

Commit 7d07e19

Browse files
authored
Valid ObjectID for simultaneous creation of parent/child (#40)
1 parent c5c181f commit 7d07e19

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7+
## Version 1.0.3 - TBD
8+
9+
### Changed
10+
11+
- Support cases where parent/child entries are created simultaneously.
12+
713
## Version 1.0.2 - 31.10.23
814

915
### Changed

lib/entity-helper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ async function getObjectId (entityName, fields, curObj) {
8585
if (IDval) try {
8686
// REVISIT: This always reads all elements -> should read required ones only!
8787
let ID = assoc.keys?.[0]?.ref[0] || 'ID'
88-
_db_data = await SELECT.one.from(assoc._target).where({[ID]: IDval}) || {}
88+
// When parent/child nodes are created simultaneously, data is taken from draft table
89+
_db_data = await SELECT.one.from(assoc._target).where({[ID]: IDval}) ||
90+
await SELECT.one.from(`${assoc._target}.drafts`).where({[ID]: IDval}) || {}
8991
} catch (e) {
9092
LOG.error("Failed to generate object Id for an association entity.", e)
9193
throw new Error("Failed to generate object Id for an association entity.", e)

tests/integration/fiori-draft-enabled.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,43 @@ describe("change log integration test", () => {
806806
const deleteTitleChange = deleteTitleChanges[0];
807807
expect(deleteTitleChange.objectID).to.equal("new title, In Preparation, France");
808808

809+
// Check object ID "bookStore.city.country.countryName.code" when creating BookStores/Books
810+
// (parent/child) at the same time.
811+
cds.services.AdminService.entities.Books["@changelog"] = [
812+
{ "=": "bookStore.city.country.countryName.code" },
813+
];
814+
815+
const createBooksAndBookStoresAction = POST.bind({}, `/odata/v4/admin/BookStores`, {
816+
ID: "48268451-8552-42a6-a3d7-67564be86634",
817+
city_ID: "60b4c55d-ec87-4edc-84cb-2e4ecd60de48",
818+
books: [
819+
{
820+
ID: "12ed5dd8-d45b-11ed-afa1-1942bd119007",
821+
title: "New title",
822+
},
823+
],
824+
});
825+
826+
await utils.apiAction(
827+
"admin",
828+
"BookStores",
829+
"48268451-8552-42a6-a3d7-67564be86634",
830+
"AdminService",
831+
createBooksAndBookStoresAction,
832+
true,
833+
);
834+
835+
const createBooksAndBookStoresChanges = await adminService.run(
836+
SELECT.from(ChangeView).where({
837+
entity: "sap.capire.bookshop.Books",
838+
attribute: "title",
839+
modification: "create",
840+
}),
841+
);
842+
expect(createBooksAndBookStoresChanges.length).to.equal(1);
843+
const createBooksAndBookStoresChange = createBooksAndBookStoresChanges[0];
844+
expect(createBooksAndBookStoresChange.objectID).to.equal("USA");
845+
809846
cds.services.AdminService.entities.Books["@changelog"] = [
810847
{ "=": "title" },
811848
{ "=": "author.name.firstName" },

0 commit comments

Comments
 (0)