fix: eager load with nested association (#2002)

This commit is contained in:
ChengLei Shao 2023-06-07 15:31:29 +08:00 committed by GitHub
parent 43f3cb7cfe
commit e8e9c038e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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];

View File

@ -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;
}