diff --git a/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts b/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts index 11f45bb71..72c499503 100644 --- a/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts +++ b/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts @@ -73,7 +73,10 @@ pgOnly()('collection inherits', () => { it('should append collection name in eager load', async () => { const rootCollection = db.collection({ name: 'assoc', - fields: [{ name: 'name', type: 'string' }], + fields: [ + { name: 'name', type: 'string' }, + { type: 'belongsToMany', name: 'other-assocs' }, + ], }); const childCollection = db.collection({ @@ -81,6 +84,11 @@ pgOnly()('collection inherits', () => { inherits: ['assoc'], }); + const otherAssoc = db.collection({ + name: 'other-assocs', + fields: [{ name: 'name', type: 'string' }], + }); + const User = db.collection({ name: 'users', fields: [ @@ -116,7 +124,7 @@ pgOnly()('collection inherits', () => { }); const users = await User.repository.find({ - appends: ['assocs'], + appends: ['assocs.other-assocs'], }); const user = users[0]; diff --git a/packages/core/database/src/eager-loading/eager-loading-tree.ts b/packages/core/database/src/eager-loading/eager-loading-tree.ts index 57d27a436..184e63277 100644 --- a/packages/core/database/src/eager-loading/eager-loading-tree.ts +++ b/packages/core/database/src/eager-loading/eager-loading-tree.ts @@ -27,6 +27,12 @@ const EagerLoadingNodeProto = { const collection = db.modelCollection.get(this.model); if (collection && collection.isParent()) { + if (!this.attributes) { + this.attributes = { + include: [], + }; + } + OptionsParser.appendInheritInspectAttribute(this.attributes.include, collection); this.inspectInheritAttribute = true; }