diff --git a/packages/database/src/__tests__/utils/toInclude.test.ts b/packages/database/src/__tests__/utils/toInclude.test.ts index c715b7e047..ae6e9d83c9 100644 --- a/packages/database/src/__tests__/utils/toInclude.test.ts +++ b/packages/database/src/__tests__/utils/toInclude.test.ts @@ -90,6 +90,7 @@ describe('toInclude', () => { association: 'bars', } ], + distinct: true, }); }); @@ -104,6 +105,7 @@ describe('toInclude', () => { attributes: [ 'col1', 'col2' ], } ], + distinct: true, }); }); @@ -118,6 +120,7 @@ describe('toInclude', () => { attributes: [ 'col1', 'col2' ], } ], + distinct: true, }); }); @@ -137,6 +140,7 @@ describe('toInclude', () => { ] } ], + distinct: true, }); }); @@ -156,6 +160,7 @@ describe('toInclude', () => { ] } ], + distinct: true, }); }); @@ -175,6 +180,7 @@ describe('toInclude', () => { ] } ], + distinct: true, }); }); @@ -196,6 +202,7 @@ describe('toInclude', () => { ] } ], + distinct: true, }); }); @@ -227,7 +234,8 @@ describe('toInclude', () => { include: ['col1'], }, } - ] + ], + distinct: true, }); }); @@ -256,6 +264,7 @@ describe('toInclude', () => { attributes: ['col1'], } ], + distinct: true, }); }); @@ -266,7 +275,6 @@ describe('toInclude', () => { }, }).toEqual({ attributes: { - include: [], exclude: ['col1'], }, }); @@ -279,18 +287,17 @@ describe('toInclude', () => { }, }).toEqual({ attributes: { - include: [], exclude: ['col1'], }, include: [ { association: 'bars', attributes: { - include: [], exclude: ['col1'], } } - ] + ], + distinct: true, }); }); @@ -356,7 +363,8 @@ describe('toInclude', () => { col1: 'val1', } } - ] + ], + distinct: true, }); }); @@ -387,7 +395,8 @@ describe('toInclude', () => { col1: 'val1', } } - ] + ], + distinct: true, }); }); diff --git a/packages/database/src/table.ts b/packages/database/src/table.ts index c4dc7ea1ad..9983b0243c 100644 --- a/packages/database/src/table.ts +++ b/packages/database/src/table.ts @@ -279,6 +279,9 @@ export class Table { }); // 添加字段后 table.options 中的 fields 并不会更新,这导致 table.getOptions() 拿不到最新的字段配置 // 所以在同时更新 table.options.fields 数组 + if (!this.options.fields) { + this.options.fields = []; + } const existIndex = this.options.fields.findIndex(field => field.name === name); if (existIndex !== -1) { this.options.fields.splice(existIndex, 1, options);