Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Entity alias is not being escaped/quoted when used in the where option using EntityManager find() method #9652

Open
1 of 18 tasks
fendy-bubbler opened this issue Dec 23, 2022 · 0 comments

Comments

@fendy-bubbler
Copy link

Issue description

Entity alias is not being escaped/quoted when used in the where option using EntityManager find() method. This causes issue when the alias hash starts with a number and it's not a valid identifier without double quotes in PostgreSQL

Expected Behavior

The query generated should quote the table aliases to avoid hashes that has number in front.

SELECT 
...
(SELECT name FROM "teacher" WHERE "teacher".id= "student".teacher_id) AS COL_A
FROM student
WHERE
  (SELECT name FROM "teacher" WHERE "teacher".id= "student".teacher_id) = 'patrick'

Actual Behavior

Aliases are not quoted when used in where clause

SELECT 
...
(SELECT name FROM "teacher" WHERE "teacher".id= "student".teacher_id) AS COL_A
FROM student
WHERE
  (SELECT name FROM "teacher" WHERE "teacher".id= student.teacher_id) = 'patrick'

Steps to reproduce

  1. Has a VirtualColumn in an Entity
  2. Has the SQL for the column to use alias in where clause or as table
@VirtualColumn({
    query: (alias) =>
      `
        SELECT name FROM "teacher" WHERE "teacher".id= ${alias}.teacher_id
      `,
  })
  teacherName?: string;
  1. Use find() with 'where` option
studentRepo.find({
    where: {
       teacherName: 'patrick',
    },
  });

My Environment

Dependency Version
Operating System MacOS 13.1
Node.js version v16.15.0
Typescript version 7.17.12
TypeORM version 0.3.11

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

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

No branches or pull requests

1 participant