mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:15:11 +00:00
fix: load parent field in inherited collection (#5044)
Some checks failed
auto-merge / push-commit (push) Has been cancelled
Build Docker Image / build-and-push (push) Has been cancelled
Build Pro Image / build-and-push (push) Has been cancelled
E2E / Build (push) Has been cancelled
NocoBase Backend Test / sqlite-test (20, false) (push) Has been cancelled
NocoBase Backend Test / sqlite-test (20, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Has been cancelled
NocoBase Backend Test / mysql-test (20, false) (push) Has been cancelled
NocoBase Backend Test / mysql-test (20, true) (push) Has been cancelled
NocoBase Backend Test / mariadb-test (20, false) (push) Has been cancelled
NocoBase Backend Test / mariadb-test (20, true) (push) Has been cancelled
Test on Windows / build (push) Has been cancelled
E2E / Core and plugins (push) Has been cancelled
E2E / plugin-workflow (push) Has been cancelled
E2E / plugin-workflow-approval (push) Has been cancelled
E2E / plugin-data-source-main (push) Has been cancelled
E2E / Comment on PR (push) Has been cancelled
Some checks failed
auto-merge / push-commit (push) Has been cancelled
Build Docker Image / build-and-push (push) Has been cancelled
Build Pro Image / build-and-push (push) Has been cancelled
E2E / Build (push) Has been cancelled
NocoBase Backend Test / sqlite-test (20, false) (push) Has been cancelled
NocoBase Backend Test / sqlite-test (20, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Has been cancelled
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Has been cancelled
NocoBase Backend Test / mysql-test (20, false) (push) Has been cancelled
NocoBase Backend Test / mysql-test (20, true) (push) Has been cancelled
NocoBase Backend Test / mariadb-test (20, false) (push) Has been cancelled
NocoBase Backend Test / mariadb-test (20, true) (push) Has been cancelled
Test on Windows / build (push) Has been cancelled
E2E / Core and plugins (push) Has been cancelled
E2E / plugin-workflow (push) Has been cancelled
E2E / plugin-workflow-approval (push) Has been cancelled
E2E / plugin-data-source-main (push) Has been cancelled
E2E / Comment on PR (push) Has been cancelled
* fix: load parent field in inherited collection * chore: test
This commit is contained in:
parent
b75fdc7f62
commit
fb57f12ba2
@ -25,6 +25,65 @@ describe.runIf(isPg())('collection inherits', () => {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
it('should load parent collection with association field', async () => {
|
||||
const User = db.collection({
|
||||
name: 'users',
|
||||
autoGenId: false,
|
||||
timestamps: false,
|
||||
fields: [
|
||||
{
|
||||
name: 'roles',
|
||||
type: 'belongsToMany',
|
||||
target: 'roles',
|
||||
through: 'rolesUsers',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
User.setField('roles', {
|
||||
type: 'belongsToMany',
|
||||
target: 'roles',
|
||||
through: 'rolesUsers',
|
||||
});
|
||||
|
||||
User.setField('id', {
|
||||
type: 'bigInt',
|
||||
primaryKey: true,
|
||||
});
|
||||
|
||||
const Role = db.collection({
|
||||
name: 'roles',
|
||||
autoGenId: false,
|
||||
fields: [
|
||||
{
|
||||
name: 'name',
|
||||
primaryKey: true,
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
name: 'users',
|
||||
type: 'belongsToMany',
|
||||
target: 'users',
|
||||
through: 'rolesUsers',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await db.sync();
|
||||
|
||||
let err;
|
||||
try {
|
||||
const child = db.collection({
|
||||
name: 'child',
|
||||
inherits: ['users'],
|
||||
});
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should append __collection with eager load', async () => {
|
||||
const Root = db.collection({
|
||||
name: 'root',
|
||||
|
@ -68,13 +68,13 @@ export class InheritedCollection extends Collection {
|
||||
for (const parent of this.parents) {
|
||||
if (parent.isInherited()) {
|
||||
for (const [name, field] of (<InheritedCollection>parent).parentFields()) {
|
||||
fields.set(name, field.options);
|
||||
fields.set(name, field);
|
||||
}
|
||||
}
|
||||
|
||||
const parentFields = parent.fields;
|
||||
for (const [name, field] of parentFields) {
|
||||
fields.set(name, field.options);
|
||||
fields.set(name, field);
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,9 +120,23 @@ export class InheritedCollection extends Collection {
|
||||
}
|
||||
|
||||
protected setParentFields() {
|
||||
for (const [name, fieldOptions] of this.parentFields()) {
|
||||
const delayFields = new Map<string, Field>();
|
||||
|
||||
for (const [name, field] of this.parentFields()) {
|
||||
if (field.isRelationField()) {
|
||||
delayFields.set(name, field);
|
||||
continue;
|
||||
}
|
||||
|
||||
this.setField(name, {
|
||||
...fieldOptions,
|
||||
...field.options,
|
||||
inherit: true,
|
||||
});
|
||||
}
|
||||
|
||||
for (const [name, field] of delayFields) {
|
||||
this.setField(name, {
|
||||
...field.options,
|
||||
inherit: true,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user