fix: eager load with nested association (#2002)
This commit is contained in:
parent
43f3cb7cfe
commit
e8e9c038e3
@ -73,7 +73,10 @@ pgOnly()('collection inherits', () => {
|
|||||||
it('should append collection name in eager load', async () => {
|
it('should append collection name in eager load', async () => {
|
||||||
const rootCollection = db.collection({
|
const rootCollection = db.collection({
|
||||||
name: 'assoc',
|
name: 'assoc',
|
||||||
fields: [{ name: 'name', type: 'string' }],
|
fields: [
|
||||||
|
{ name: 'name', type: 'string' },
|
||||||
|
{ type: 'belongsToMany', name: 'other-assocs' },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const childCollection = db.collection({
|
const childCollection = db.collection({
|
||||||
@ -81,6 +84,11 @@ pgOnly()('collection inherits', () => {
|
|||||||
inherits: ['assoc'],
|
inherits: ['assoc'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const otherAssoc = db.collection({
|
||||||
|
name: 'other-assocs',
|
||||||
|
fields: [{ name: 'name', type: 'string' }],
|
||||||
|
});
|
||||||
|
|
||||||
const User = db.collection({
|
const User = db.collection({
|
||||||
name: 'users',
|
name: 'users',
|
||||||
fields: [
|
fields: [
|
||||||
@ -116,7 +124,7 @@ pgOnly()('collection inherits', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const users = await User.repository.find({
|
const users = await User.repository.find({
|
||||||
appends: ['assocs'],
|
appends: ['assocs.other-assocs'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const user = users[0];
|
const user = users[0];
|
||||||
|
@ -27,6 +27,12 @@ const EagerLoadingNodeProto = {
|
|||||||
const collection = db.modelCollection.get(this.model);
|
const collection = db.modelCollection.get(this.model);
|
||||||
|
|
||||||
if (collection && collection.isParent()) {
|
if (collection && collection.isParent()) {
|
||||||
|
if (!this.attributes) {
|
||||||
|
this.attributes = {
|
||||||
|
include: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
OptionsParser.appendInheritInspectAttribute(this.attributes.include, collection);
|
OptionsParser.appendInheritInspectAttribute(this.attributes.include, collection);
|
||||||
this.inspectInheritAttribute = true;
|
this.inspectInheritAttribute = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user