nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.getOne() does not return any result with queryBuilder.select()

natikos opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

const item = await this.documentRepository
      .createQueryBuilder('item')
      .innerJoin('item.parent', 'parent')
      .where('item.id = :itemId', { itemId })
      .select(['item.id', 'parent.id'])
      .getOne()

This builds correct raw SQL query:

query : 
SELECT 
  `item`.`id` AS `item_id`, 
  `parent`.`id` AS `parent_id` 
FROM 
  `item` `item` 
  INNER JOIN `parent` `parent` ON `parent`.`id` = `item`.`parentId` 
WHERE 
  (`item`.`id` = ?) -- PARAMETERS: [1]

When I run the query in my SQL client I got result, but when I run queryBuilder with getOne() it returns nothing. getRawOne() works as expected.

Minimum reproduction code

https://github.com

Steps to reproduce

No response

Expected behavior

Result must be returned with getOne().

Package version

8.0.2

NestJS version

8.0.0

Node.js version

16.19.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

This is not related wit Nest but Typeorm as @nestjs/typeorm change nothing on typeorm's behavior.

Please report to them instead.
npm docs typeorm

tip: you can see the query generated by using .getQuery()

https://typeorm.io