Skip to content

Not return nested objects

I hav a problem with typeorm, I ahve na queryBuilder like below:

        const projects = await this.conn.getRepository(UserProjectRelations).createQueryBuilder("userProject")
            .innerJoin("userProject.userId", "user", " = :userId", { userId: })
            .leftJoinAndSelect("userProject.projectId", "project")

        return await projects.getRawOne();

why this query return me this data:

RowDataPacket {
  userProject_id: 67,
  userProject_status: 'Owner',
  userProject_lastUpdate: 2021-03-24T21:13:32.000Z,
  project_id: 21,
  project_name: 'nest',
  project_appName: 'Test123!',
  project_createdAt: 2021-03-24T20:47:40.000Z,
  project_shortDescription: null,

instead of this:

    userProject: {
    project: {
      "createdAt": "..."

i need to return nested object instead of using alias, can someone tell me how to do this with using queryBuilder?

thanks for any help!



You have to use getOne not getRawOne.