Merge branch 'next' into develop

This commit is contained in:
nocobase[bot] 2024-12-29 00:30:29 +00:00
commit bee085710d
2 changed files with 40 additions and 0 deletions

View File

@ -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: {

View File

@ -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 }) => {