Skip to content

Fix withSql referencing a named shape column by its name (#903) - #909

Merged
IlyaSemenov merged 1 commit into
romeerez:mainfrom
IlyaSemenov:IlyaSemenov/withsql-a-shape-column-with-name-is-declared-by
Nov 17, 2026
Merged

IlyaSemenov merged 1 commit into
romeerez:mainfrom
IlyaSemenov:IlyaSemenov/withsql-a-shape-column-with-name-is-declared-by

Conversation

@IlyaSemenov

@IlyaSemenov IlyaSemenov commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #903.

withSql declares the CTE columns by the keys of the shape, but selections, conditions, and joins refer to a column by its name(). For a shape column with name(), the query fails with column score.author_id does not exist.

With this PR, withSql ignores name() of the shape columns, the same as with does for the columns of a sub-query: the CTE columns are declared and referenced by the shape keys.

Motivation

Another follow-up to #904 and #905, for the same ACL optimization: a withSql CTE whose shape reuses columns with name().

Verification

Added database-backed tests for withSql with a named column: referenced in select and where, selected with all columns, and used in another CTE. The first fails without the fix, and all pass with it. pnpm verify passes.

Checklist

  • I have read the final diff and can explain every change.
  • I will address review feedback.
  • I added a changeset (pnpm changeset) if this PR includes a feature or bug fix in a published package.

@netlify

netlify Bot commented Nov 17, 2026

Copy link
Copy Markdown

👷 Deploy request for orchid-orm pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ccd8fb2

@IlyaSemenov
IlyaSemenov merged commit 3dc6615 into romeerez:main Nov 17, 2026
3 checks passed
@IlyaSemenov
IlyaSemenov deleted the IlyaSemenov/withsql-a-shape-column-with-name-is-declared-by branch November 17, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

withSql: a shape column with name() is declared by its key but referenced by its name

1 participant