mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
Merge branch 'next' into develop
This commit is contained in:
commit
bee085710d
@ -31,6 +31,40 @@ describe('collections repository', () => {
|
||||
await app.destroy();
|
||||
});
|
||||
|
||||
it('should not create collection already exists', async () => {
|
||||
db.collection({
|
||||
name: 'jobs',
|
||||
fields: [
|
||||
{
|
||||
type: 'string',
|
||||
name: 'title',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await db.sync();
|
||||
|
||||
let err;
|
||||
|
||||
try {
|
||||
await Collection.repository.create({
|
||||
values: {
|
||||
name: 'jobs',
|
||||
fields: [
|
||||
{
|
||||
type: 'string',
|
||||
name: 'title',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should load through table with foreignKey', async () => {
|
||||
await Collection.repository.create({
|
||||
values: {
|
||||
|
@ -91,6 +91,12 @@ export class PluginDataSourceMainServer extends Plugin {
|
||||
|
||||
this.app.db.on('collections.beforeCreate', beforeCreateForViewCollection(this.db));
|
||||
|
||||
this.app.db.on('collections.beforeCreate', async (model: CollectionModel, options) => {
|
||||
if (this.app.db.getCollection(model.get('name')) && model.get('from') !== 'db2cm' && !model.get('isThrough')) {
|
||||
throw new Error(`Collection named ${model.get('name')} already exists`);
|
||||
}
|
||||
});
|
||||
|
||||
this.app.db.on(
|
||||
'collections.afterSaveWithAssociations',
|
||||
async (model: CollectionModel, { context, transaction }) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user