I hav a problem with typeorm, I ahve na queryBuilder
like below:
JavaScript
x
7
1
const projects = await this.conn.getRepository(UserProjectRelations).createQueryBuilder("userProject")
2
.innerJoin("userProject.userId", "user", "user.id = :userId", { userId: currentUser.id })
3
.leftJoinAndSelect("userProject.projectId", "project")
4
5
6
return await projects.getRawOne();
7
why this query return me this data:
JavaScript
1
11
11
1
RowDataPacket {
2
userProject_id: 67,
3
userProject_status: 'Owner',
4
userProject_lastUpdate: 2021-03-24T21:13:32.000Z,
5
project_id: 21,
6
project_name: 'nest',
7
project_appName: 'Test123!',
8
project_createdAt: 2021-03-24T20:47:40.000Z,
9
project_shortDescription: null,
10
}
11
instead of this:
JavaScript
1
13
13
1
{
2
userProject: {
3
"id":67,
4
"status":"Owner",
5
"lastUpdate":"..."
6
},
7
project: {
8
"name":"test",
9
"appName":"Test123!",
10
"createdAt": "..."
11
}
12
}
13
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!
Advertisement
Answer
You have to use getOne
not getRawOne
.