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

Brackets syntax failed when use where with object literal #3685

Closed
vietthang opened this issue Feb 21, 2019 · 12 comments
Closed

Brackets syntax failed when use where with object literal #3685

vietthang opened this issue Feb 21, 2019 · 12 comments

Comments

@vietthang
Copy link

Issue type:

[ ] question
[x ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[ x] 0.2.12 (or put your version here)

Steps to reproduce or a small repository showing the problem:

When I use Brackets syntax with object literal as below:

const generatedSql = entityManager
    .createQueryBuilder()
    .from(Product, 'Product')
    .where(new Brackets(qb => qb.where({ id: 1 })))

I got exception:

(node:97360) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'hasMetadata' of undefined
    at SelectQueryBuilder.QueryBuilder.computeWhereParameter (/Users/thangnv/Develop/typeorm-report/src/query-builder/QueryBuilder.ts:763:47)
    at SelectQueryBuilder.where (/Users/thangnv/Develop/typeorm-report/src/query-builder/SelectQueryBuilder.ts:690:32)
    at Brackets.entityManager.createQueryBuilder.from.where.typeorm_1.Brackets.qb [as whereFactory] (/Users/thangnv/Develop/typeorm-report/src/test.ts:27:34)
    at SelectQueryBuilder.QueryBuilder.computeWhereParameter (/Users/thangnv/Develop/typeorm-report/src/query-builder/QueryBuilder.ts:750:19)
    at SelectQueryBuilder.where (/Users/thangnv/Develop/typeorm-report/src/query-builder/SelectQueryBuilder.ts:690:32)
    at test (/Users/thangnv/Develop/typeorm-report/src/test.ts:27:6)
    at process._tickCallback (internal/process/next_tick.js:68:7)

From my quick research, the issue come from this line:

if (this.expressionMap.mainAlias!.hasMetadata) {

Seem like omit null check in mainAlias causes this issue.

Thanks,

@pie6k

This comment has been minimized.

@AndKiel
Copy link

AndKiel commented Apr 16, 2019

Encountered the same thing today.
Any news on this?

EDIT:
It's mysql / @0.2.16 in my case.

@lucashsilva

This comment has been minimized.

@abstractmatter

This comment has been minimized.

@viczam
Copy link

viczam commented Oct 31, 2019

And news on this?

@lucasbemol

This comment has been minimized.

@guilhermetelles

This comment has been minimized.

@serhiisol
Copy link

Having the same problem with "typeorm": "0.2.21"

haoyuhu added a commit to haoyuhu/typeorm that referenced this issue Mar 11, 2020
haoyuhu added a commit to haoyuhu/typeorm that referenced this issue Mar 11, 2020
@pleerock
Copy link
Member

@Kononnable people keep using .where({ ... }) syntax when its supposed to be internal functionality used by ORM itself and thus have some bugs. We'll need to figure out query builder refactoring to prevent this unintended usage.

@kevindashgit
Copy link
Contributor

@Kononnable people keep using .where({ ... }) syntax when its supposed to be internal functionality used by ORM itself and thus have some bugs. We'll need to figure out query builder refactoring to prevent this unintended usage.

...and what's the intended usage?

@serg06
Copy link

serg06 commented Mar 28, 2022

@kevindashgit I believe this is the intended usage:

.where('id = :id', {id});

@kirill-homez
Copy link

kirill-homez commented Sep 19, 2023

@Kononnable people keep using .where({ ... }) syntax when its supposed to be internal functionality used by ORM itself and thus have some bugs. We'll need to figure out query builder refactoring to prevent this unintended usage.

Is this still true? Is there a place in the documentation where this is clearly stated?

I see that the preferred one in the docs is

.where('id = :id', {id});

but I've never seen that .where({ ... }) is not intended to be used.

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