Skip to content

leftJoinAndMapOne doesn't add property when custom query builder is used #8705

@prateekkathal

Description

@prateekkathal

Issue Description

Coming from #1882. Running a query builder in leftJoinAndMapOne doesn't map to property.

Expected Behavior

leftJoinAndMapOne should map to the provided property.

Actual Behavior

I am trying to do something like

const [venues, venuesCount] = this.venuesRepository
  .createQueryBuilder("Venue")
  .leftJoinAndSelect("Venue.city", "city")
  .leftJoinAndMapOne(
    "Venue.eventStats",
    (qb) =>
      qb
        .from("events", "Event")
        .select('"venueId"')
        .addSelect(`MAX("capacity")`, "maxVenueCapacity")
        .addSelect(`COUNT("venueId")`, "eventsCount")
        .groupBy('"venueId"'),
    "Event",
    "Venue.id = Event.venueId"
  )
  .where(`Venue.cityId = :cityId`, { cityId: "someCityId" })
  .orderBy(`eventCount`, `DESC`)
  .getManyAndCount();

And my model has

interface EventStats {
  maxVenueCapacity: number;
  eventsCount: number;
}

@Entity()
class Venue {
  eventStats: EventStats;
}

at the end venues[].eventStats is not added.

// include the output in code tags like these!

Steps to Reproduce

  1. Use the code I provided above to create a similar query.
  2. Run the query and check if the mapped property is getting added.

My Environment

Dependency Version
Operating System Docker Node Alpine Image
Node.js version 14.17.0
Typescript version 4.5.4
TypeORM version 0.2.41

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
postgres yes

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions