如何在typeorm0.1.3中将所有关联数据映射到单个实体的属性

时间:2018-07-06 04:56:00

标签: typeorm

我将在以下环境中将我的employee映射到其父实体employeeLeaveApprovers。根据文档,我尝试使用leftJoinAndMapMany方法,但无法获得预期的结果

默认结果数据

"employeeLeaveApprovers": [
        {
            "id": 56,
            "createdAt": "2018-07-03T01:52:41.960Z",
            "updatedAt": "2018-07-03T01:52:41.960Z",
            "createdBy": 1,
            "updatedBy": null,
            "state": 1,
            "version": 1,
            "approverId": 2,
            "required": true,
            "employee": {
                "id": 2,
                "firstName": "heng",
                "lastName": "Sopheak"
            }
        }
   ];

期望结果

"employeeLeaveApprovers": [
        {
            "id": 56,
            "createdAt": "2018-07-03T01:52:41.960Z",
            "updatedAt": "2018-07-03T01:52:41.960Z",
            "createdBy": 1,
            "updatedBy": null,
            "state": 1,
            "version": 1,
            "approverId": 2,
            "required": true,
            "firstName": "heng",
            "lastName": "Sopheak"
        }
   ];

0 个答案:

没有答案