Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only consider persisted columns for simple operations #592

Merged
merged 8 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,9 @@ class CQN2SQLRenderer {
if (_with) _add(_with, x => this.expr(x))
function _add(data, sql4) {
for (let c in data) {
if (!elements || (c in elements && !elements[c].virtual)) {
if (cds.unfold && elements?.[c].is_struct) continue // skip structs from universal csn
const columnExistsInDatabase =
elements && c in elements && !elements[c].virtual && !elements[c].isAssociation && !elements[c].value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elements && c in elements && !elements[c].virtual && !elements[c].isAssociation && !elements[c].value
c in elements && !elements[c].virtual && !elements[c].isAssociation && !elements[c].value

check below ensures this already

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If elements is undefined we'd get a type error:

> 'bar' in elements
VM240:1 Uncaught TypeError: Cannot use 'in' operator to search for 'bar' in undefined
    at <anonymous>:1:7

if (!elements || columnExistsInDatabase) {
columns.push({ name: c, sql: sql4(data[c]) })
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/bookshop/db/data/sap.capire.bookshop-Authors.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ID;name;dateOfBirth;placeOfBirth;dateOfDeath;placeOfDeath
101;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire
107;Charlotte Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire
150;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland
170;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England
ID;name;dateOfBirth;placeOfBirth;dateOfDeath;placeOfDeath; city; street;
101;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire; Bradford; 1 Main Street
107;Charlotte Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire; Bradford; 2 Main Street
150;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland; Baltimore; 1 Main Street
170;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England; London; 1 Main Street
6 changes: 6 additions & 0 deletions test/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ entity Books : managed {
currency : Currency;
image : LargeBinary @Core.MediaType : 'image/png';
footnotes: array of String;

authorsAddress: String = author.address;
}

entity Authors : managed {
Expand All @@ -22,6 +24,10 @@ entity Authors : managed {
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books on books.author = $self;

street: String;
city: String;
address: String = street || ', ' || city;
}

/** Hierarchically organized Code List for Genres */
Expand Down
Loading