Skip to content

foreign key of association not included in columns for wildcard select from subquery #1127

@patricebender

Description

@patricebender

Given the following query:

> q = cds.ql`SELECT from (SELECT from (select from ${Books} as inner { author } ) as mid ) as outer where author = 42`
cds.ql {
  SELECT: {
    from: {
      SELECT: {
        from: {
          SELECT: {
            from: { ref: [ 'sap.capire.bookshop.Books' ], as: 'inner' },
            columns: [ { ref: [ 'author' ] } ]
          },
          as: 'mid'
        }
      },
      as: 'outer'
    },
    where: [ { ref: [ 'author' ] }, '=', { val: 42 } ]
  }
}

the forSQL transformation misses bubbling up the foreign key from the innermost selects association author:

> q.forSQL()
cds.ql {
  SELECT: {
    from: {
      SELECT: {
        from: {
          SELECT: {
            from: { ref: [ 'sap.capire.bookshop.Books' ], as: 'inner' },
            columns: [ { ref: [ 'inner', 'author_ID' ] } ]
          },
          as: 'mid'
        },
        columns: []
      },
      as: 'outer'
    },
    where: [ { ref: [ 'outer', 'author_ID' ] }, '=', { val: 42 } ],
    columns: []
  }
}

→ This is due to a mechanism which prevents us from duplicating a foreign key for a wildcard select. This case kicks in if we have a flat CSN, which contains an association and it's foreign key. However, in this case, it does only hold the association, hence we should flatten the association.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcqn4sqlall issues related to db-service/cqn4sql

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions