TypeORM 2단 Join
- 1단계 Join
- relations 배열에 [조인할 컬럼A] 을 명시
- 2단계 Join
- relations 배열에 [조인할 컬럼A].[조인할 컬럼B] 을 명시
case. mapping table read
const memberStrategyList = await this.MemberStrategyRepo.find({
order: {
create_date: 'DESC',
},
relations: [
'operationMemberList',
'operationMemberList.operation_customer',
],
});
console.log(JSON.stringify(memberStrategyList, null, 4));
[
{
"strategy_code": "2",
"strategy_name": "찬규의 테스트 케이스",
"invest_type": "StableIncome",
"strategy_explanation": "찬규의 테스트 관련 전략 설명란 입니다.",
"operation_yes_no": true,
"alarm_setting": false,
"open_yes_no": true,
"image_url": "https://algoridang.s3.ap-northeast-2.amazonaws.com/common/1627272438714d_thumb01.jpeg",
"create_date": "2021-07-26T06:22:25.308Z",
"deleteAt": null,
"maker_id": "changyu.park1@gmail.com",
"operator_id": "blue_rose17@naver.com",
"operationMemberList": []
},
{
"strategy_code": "1",
"strategy_name": "찬규의 테스트 케이스",
"invest_type": "StableIncome",
"strategy_explanation": "찬규의 테스트 관련 전략 설명란 입니다.",
"operation_yes_no": true,
"alarm_setting": false,
"open_yes_no": true,
"image_url": "https://algoridang.s3.ap-northeast-2.amazonaws.com/common/1627272438714d_thumb01.jpeg",
"create_date": "2021-07-26T05:50:05.695Z",
"deleteAt": null,
"maker_id": "changyu.park1@gmail.com",
"operator_id": "changyu.park1@gmail.com",
"operationMemberList": [
{
"strategy_code": "1",
"operation_customer_id": "blue_rose17@naver.com",
"operation_customer": {
"email_id": "blue_rose17@naver.com",
"password": "$2b$10$VVtY3jFKnBk9B26Qws6uqezjE2QxKniHWB9jr9/w/wM9DH8gFpkW.",
"member_name": "Test_Taker1",
"role": "Normal"
}
}
]
}
]