@@ -1720,4 +1720,71 @@ describe('path expression within infix filter following exists predicate', () =>
1720
1720
)` ,
1721
1721
)
1722
1722
} )
1723
+
1724
+ it ( 'renders inner joins for the path expression at the leaf of scoped queries (DELETE)' , ( ) => {
1725
+ // subquery has flat author_ID, which is not part of client csn
1726
+ const forNodeModel = cds . compile . for . nodejs ( JSON . parse ( JSON . stringify ( cds . model ) ) )
1727
+ let query = DELETE . from ( 'bookshop.Authors:books[genre.name = null]' )
1728
+
1729
+ const transformed = cqn4sql ( query , forNodeModel )
1730
+ const subquery = cds . ql `
1731
+ SELECT books.ID from bookshop.Books as books
1732
+ inner join bookshop.Genres as genre on genre.ID = books.genre_ID
1733
+ WHERE EXISTS (
1734
+ SELECT 1 from bookshop.Authors as Authors where Authors.ID = books.author_ID
1735
+ ) and genre.name = null`
1736
+ const expected = DELETE . from ( 'bookshop.Books' ) . alias ( 'books2' )
1737
+ expected . DELETE . where = [ { list : [ { ref : [ 'books2' , 'ID' ] } ] } , 'in' , subquery ]
1738
+ expect ( transformed ) . to . deep . equal ( expected )
1739
+ } )
1740
+ it ( 'renders inner joins for the path expression at the leaf of scoped queries, two assocs (DELETE)' , ( ) => {
1741
+ // subquery has flat author_ID, which is not part of client csn
1742
+ const forNodeModel = cds . compile . for . nodejs ( JSON . parse ( JSON . stringify ( cds . model ) ) )
1743
+ let query = DELETE . from ( 'bookshop.Authors:books[genre.parent.name = null]' )
1744
+
1745
+ const transformed = cqn4sql ( query , forNodeModel )
1746
+ const subquery = cds . ql `
1747
+ SELECT books.ID from bookshop.Books as books
1748
+ inner join bookshop.Genres as genre on genre.ID = books.genre_ID
1749
+ inner join bookshop.Genres as parent on parent.ID = genre.parent_ID
1750
+ WHERE EXISTS (
1751
+ SELECT 1 from bookshop.Authors as Authors where Authors.ID = books.author_ID
1752
+ ) and parent.name = null`
1753
+ const expected = DELETE . from ( 'bookshop.Books' ) . alias ( 'books2' )
1754
+ expected . DELETE . where = [ { list : [ { ref : [ 'books2' , 'ID' ] } ] } , 'in' , subquery ]
1755
+ expect ( transformed ) . to . deep . equal ( expected )
1756
+ } )
1757
+ it ( 'renders inner joins for the path expression at the leaf of scoped queries (UPDATE)' , ( ) => {
1758
+ // subquery has flat author_ID, which is not part of client csn
1759
+ const forNodeModel = cds . compile . for . nodejs ( JSON . parse ( JSON . stringify ( cds . model ) ) )
1760
+ let query = UPDATE . entity ( 'bookshop.Authors:books[genre.name = null]' )
1761
+
1762
+ const transformed = cqn4sql ( query , forNodeModel )
1763
+ const subquery = cds . ql `
1764
+ SELECT books.ID from bookshop.Books as books
1765
+ inner join bookshop.Genres as genre on genre.ID = books.genre_ID
1766
+ WHERE EXISTS (
1767
+ SELECT 1 from bookshop.Authors as Authors where Authors.ID = books.author_ID
1768
+ ) and genre.name = null`
1769
+ const expected = UPDATE . entity ( 'bookshop.Books' ) . alias ( 'books2' )
1770
+ expected . UPDATE . where = [ { list : [ { ref : [ 'books2' , 'ID' ] } ] } , 'in' , subquery ]
1771
+ expect ( transformed ) . to . deep . equal ( expected )
1772
+ } )
1773
+ it ( 'renders inner joins for the path expression at the leaf of scoped queries, two assocs (DELETE)' , ( ) => {
1774
+ // subquery has flat author_ID, which is not part of client csn
1775
+ const forNodeModel = cds . compile . for . nodejs ( JSON . parse ( JSON . stringify ( cds . model ) ) )
1776
+ let query = UPDATE . entity ( 'bookshop.Authors:books[genre.parent.name = null]' )
1777
+
1778
+ const transformed = cqn4sql ( query , forNodeModel )
1779
+ const subquery = cds . ql `
1780
+ SELECT books.ID from bookshop.Books as books
1781
+ inner join bookshop.Genres as genre on genre.ID = books.genre_ID
1782
+ inner join bookshop.Genres as parent on parent.ID = genre.parent_ID
1783
+ WHERE EXISTS (
1784
+ SELECT 1 from bookshop.Authors as Authors where Authors.ID = books.author_ID
1785
+ ) and parent.name = null`
1786
+ const expected = UPDATE . entity ( 'bookshop.Books' ) . alias ( 'books2' )
1787
+ expected . UPDATE . where = [ { list : [ { ref : [ 'books2' , 'ID' ] } ] } , 'in' , subquery ]
1788
+ expect ( transformed ) . to . deep . equal ( expected )
1789
+ } )
1723
1790
} )
0 commit comments