Skip to content

Commit

Permalink
do not render an on-condition if none is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
patricebender committed Nov 18, 2024
1 parent 7fd4859 commit 2e439b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ class CQN2SQLRenderer {
return _aliased(this.quote(this.name(z)))
}
if (from.SELECT) return _aliased(`(${this.SELECT(from)})`)
if (from.join)
return `${this.from(from.args[0])} ${from.join} JOIN ${this.from(from.args[1])} ON ${this.where(from.on)}`
if (from.join) {
const joinCondition = from.on ? ` ON ${this.where(from.on)}` : '';
return `${this.from(from.args[0])} ${from.join} JOIN ${this.from(from.args[1])}${joinCondition}`;
}
}

/**
Expand Down
10 changes: 5 additions & 5 deletions test/scenarios/bookshop/read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ describe('Bookshop - Read', () => {
}
})

it('cross joins w/o on condition', async () => {
it('cross joins without on condition', async () => {
const query = SELECT.from('sap.capire.bookshop.Books as Books, sap.capire.bookshop.Authors as Authors')
.columns('Books.title', 'Authors.name as author')
.where('Books.author_ID = Authors.ID')
const queryWithPaths = SELECT.from('sap.capire.bookshop.Books').columns('title', 'author.name as author')
const res = await cds.db.run(query)
const resWithPaths = await cds.db.run(queryWithPaths)
expect(res).to.deep.eq(resWithPaths)
const pathExpressionQuery = SELECT.from('sap.capire.bookshop.Books').columns('title', 'author.name as author')
const crossJoinResult = await cds.db.run(query)
const pathExpressionResult = await cds.db.run(pathExpressionQuery)
expect(crossJoinResult).to.deep.eq(pathExpressionResult)
})
})

0 comments on commit 2e439b1

Please sign in to comment.