leftJoinAndMapMany is not mapping the result to the property when I pass a Subquery to the second argument

See original GitHub issue

Issue type: [X] bug

Database system/driver: [X] postgres

TypeORM version: [X] latest

Steps to reproduce:

  1. Clone this repo
  2. npm install && tsc
  3. npm start

These are the entities:

@Entity()
export class Category {
    @PrimaryGeneratedColumn()
    id: number;
    @Column()
    name: string;

    posts: Post[];
}

@Entity()
export class Post {
    @PrimaryGeneratedColumn()
    id: number;
    @Column()
    title: string;
    @Column('int')
    categoryId: number;
}

And this is how I build the queries:

This one returns the list of Posts:

connection.createQueryBuilder().select('category').from(Category, 'category')
              .leftJoinAndMapMany('category.posts', Post, 'post', 'post.categoryId = category.id');

This one does not:

connection.createQueryBuilder().select('category').from(Category, 'category')
                    .leftJoinAndMapMany('category.posts', qb => qb.select().from(Post, 'post'), 'post', 'post."categoryId" = category.id');

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
pleerockcommented, Jan 7, 2019

I’m going to deprecate joinAndMap methods in 0.4.0 and don’t recommend to use them. Alternative is to execute a separate query, if you need to have it in the same query consider using raw query.

3reactions
jimOnAircommented, Apr 20, 2022

Is there any solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

leftJoinAndMapMany is not mapping the result to the property ...
leftJoinAndMapMany is not mapping the result to the property when I pass a Subquery to the second argument ; Issue type: [X] bug...
Read more >
TypeORM - Query Builder with Subquery - DEV Community ‍ ‍
Building a simple SELECT query with entities is easy. However, this is not enough for creating graphs or displaying calculated results on the ......
Read more >
SelectQueryBuilder | typeorm
It will assume that there is a single row of selecting data, and mapped result will be a single selected value. Given entity...
Read more >
Is it possible to use subquery in leftJoinAndSelect in TypeORM
Using the SubQueryFactory option does not automatically create the on clause as the condition as it cannot know what the underlying query's ...
Read more >
https://unpkg.com/typeorm@0.2.7/query-builder/Sele...
subQuery (): SelectQueryBuilder<any>; /** * Creates SELECT query. ... that there are multiple rows of selecting data, and mapped result will be an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found