mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 04:07:50 +08:00
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 () => {
|
||||
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];
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user