fix: expand virtual column query in WHERE clause conditions by dikshit-n · Pull Request #12844 · typeorm/typeorm · GitHub
Skip to content

fix: expand virtual column query in WHERE clause conditions - #12844

Open
dikshit-n wants to merge 2 commits into
typeorm:masterfrom
dikshit-n:fix/virtual-column-where-clause
Open

fix: expand virtual column query in WHERE clause conditions#12844
dikshit-n wants to merge 2 commits into
typeorm:masterfrom
dikshit-n:fix/virtual-column-where-clause

Conversation

@dikshit-n

Copy link
Copy Markdown

Summary

Fixes #11616 — VirtualColumn throws error when used in WHERE conditions.

When a @VirtualColumn is used in a WHERE clause with createQueryBuilder object-style conditions, TypeORM incorrectly tries to reference the virtual property name as a literal database column, which does not exist.

Changes

File: src/query-builder/QueryBuilder.ts

  • getPredicates(): Now detects virtual columns and expands the query expression in WHERE conditions instead of using the non-existent column path.
  • buildConditionForVirtualColumn() (new): Builds SQL WHERE conditions for virtual columns by wrapping the computed query expression in appropriate operator syntax. Handles Equal, MoreThan, LessThan, Like, In, Not, And, Or, and other operators.
  • buildOperatorConditionForVirtualColumn() (new): Handles FindOperator types specifically for virtual column conditions.
  • getWhereCondition(): Routes virtual column predicates to the new handler.

File: test/functional/columns/virtual-columns/virtual-columns.test.ts

  • Added test: should expand virtual column in WHERE clause with QueryBuilder object-style condition

Example

Before (broken — causes Unknown column 'user.fullName' in 'where clause'):

WHERE `user`.`fullName` = 'John Doe'

After (fixed):

WHERE (CONCAT(`user`.firstName, ' ', `user`.lastName)) = 'John Doe'

Testing

TypeScript compiles cleanly with pnpm typecheck. The new test verifies that the WHERE clause uses the expanded query expression.

Closes #11616

@github-actions github-actions Bot added the linked-issue PR references an issue label Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added the possible-duplicate PR may duplicate an existing open PR label Sep 6, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compliance violation linked-issue PR references an issue possible-duplicate PR may duplicate an existing open PR

Development

Successfully merging this pull request may close these issues.

VirtualColumn throws error when used in WHERE conditions

1 participant