diff --git a/packages/core/database/src/__tests__/relation-repository/has-many-repository.test.ts b/packages/core/database/src/__tests__/relation-repository/has-many-repository.test.ts index 659c4a70b..a3f53dd59 100644 --- a/packages/core/database/src/__tests__/relation-repository/has-many-repository.test.ts +++ b/packages/core/database/src/__tests__/relation-repository/has-many-repository.test.ts @@ -249,7 +249,7 @@ describe('has many repository', () => { expect(p1.title).toEqual('u1t1'); }); - test('find', async () => { + test('find with has many', async () => { const u1 = await User.repository.create({ values: { name: 'u1' } }); const t1 = await Tag.repository.create({ values: { name: 't1' } }); diff --git a/packages/core/database/src/repository.ts b/packages/core/database/src/repository.ts index 00c93ddf4..c52a278ae 100644 --- a/packages/core/database/src/repository.ts +++ b/packages/core/database/src/repository.ts @@ -269,7 +269,12 @@ export class Repository { + return ( + Object.keys(include.where || {}).length > 0 || JSON.stringify(opts?.filter)?.includes(include.association) + ); + }), + } as any) ).map((row) => { return { row, pk: row.get(primaryKeyField) }; }); @@ -278,6 +283,16 @@ export class Repository id['pk']), @@ -297,7 +312,7 @@ export class Repository