|
|
@@ -26,10 +26,17 @@ export abstract class GenericCrudService<T extends ObjectLiteral> {
|
|
|
const skip = (page - 1) * pageSize;
|
|
|
const query = this.repository.createQueryBuilder('entity');
|
|
|
|
|
|
- // 添加关联关系
|
|
|
+ // 添加关联关系(支持嵌套关联,如 ['contract', 'contract.client'])
|
|
|
if (relations.length > 0) {
|
|
|
relations.forEach(relation => {
|
|
|
- query.leftJoinAndSelect(`entity.${relation}`, relation);
|
|
|
+ const parts = relation.split('.');
|
|
|
+ let currentAlias = 'entity';
|
|
|
+
|
|
|
+ parts.forEach((part, index) => {
|
|
|
+ const newAlias = index === 0 ? part : `${currentAlias}_${part}`;
|
|
|
+ query.leftJoinAndSelect(`${currentAlias}.${part}`, newAlias);
|
|
|
+ currentAlias = newAlias;
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|